image_resize_dimensions example


    public function resize( $max_w$max_h$crop = false ) {
        if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
            return true;
        }

        $dims = image_resize_dimensions( $this->size['width']$this->size['height']$max_w$max_h$crop );
        if ( ! $dims ) {
            return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ) );
        }

        list( $dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h ) = $dims;

        if ( $crop ) {
            return $this->crop( $src_x$src_y$src_w$src_h$dst_w$dst_h );
        }

        // Execute the resize.
$full_width  = $imagesize[0];
        $full_height = $imagesize[1];
    } else {
        $full_width  = (int) $image_meta['width'];
        $full_height = (int) $image_meta['height'];
    }

    $possible_sizes = array();

    // Skip registered sizes that are too large for the uploaded image.     foreach ( $registered_sizes as $size_name => $size_data ) {
        if ( image_resize_dimensions( $full_width$full_height$size_data['width']$size_data['height']$size_data['crop'] ) ) {
            $possible_sizes[ $size_name ] = $size_data;
        }
    }

    if ( empty( $image_meta['sizes'] ) ) {
        $image_meta['sizes'] = array();
    }

    /* * Remove sizes that already exist. Only checks for matching "size names". * It is possible that the dimensions for a particular size name have changed. * For example the user has changed the values on the Settings -> Media screen. * However we keep the old sub-sizes with the previous dimensions * as the image may have been used in an older post. */
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' )$this->file );
    }

    /** * @param int $max_w * @param int $max_h * @param bool|array $crop * @return resource|GdImage|WP_Error */
    protected function _resize( $max_w$max_h$crop = false ) {
        $dims = image_resize_dimensions( $this->size['width']$this->size['height']$max_w$max_h$crop );

        if ( ! $dims ) {
            return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' )$this->file );
        }

        list( $dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h ) = $dims;

        $resized = wp_imagecreatetruecolor( $dst_w$dst_h );
        imagecopyresampled( $resized$this->image, $dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h );

        if ( is_gd_image( $resized ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.