wp_imagecreatetruecolor example


    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 ) ) {
            $this->update_size( $dst_w$dst_h );
            return $resized;
        }

        return new WP_Error( 'image_resize_error', __( 'Image resize failed.' )$this->file );
    }

    /** * Create multiple smaller images from a single source. * * Attempts to create all sub-sizes and returns the meta data at the end. This * may result in the server running out of resources. When it fails there may be few * "orphaned" images left over as the meta data is never returned and saved. * * As of 5.3.0 the preferred way to do this is with `make_subsize()`. It creates * the new images one at a time and allows for the meta data to be saved after * each new image is created. * * @since 3.5.0 * * @param array $sizes { * An array of image size data arrays. * * Either a height or width must be provided. * If one of the two is set to null, the resize will * maintain aspect ratio according to the source image. * * @type array ...$0 { * Array of height, width values, and whether to crop. * * @type int $width Image width. Optional if `$height` is specified. * @type int $height Image height. Optional if `$width` is specified. * @type bool|array $crop Optional. Whether to crop the image. Default false. * } * } * @return array An array of resized images' metadata by size. */

function _flip_image_resource( $img$horz$vert ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' );

    $w   = imagesx( $img );
    $h   = imagesy( $img );
    $dst = wp_imagecreatetruecolor( $w$h );

    if ( is_gd_image( $dst ) ) {
        $sx = $vert ? ( $w - 1 ) : 0;
        $sy = $horz ? ( $h - 1 ) : 0;
        $sw = $vert ? -$w : $w;
        $sh = $horz ? -$h : $h;

        if ( imagecopyresampled( $dst$img, 0, 0, $sx$sy$w$h$sw$sh ) ) {
            imagedestroy( $img );
            $img = $dst;
        }
    }
Home | Imprint | This part of the site doesn't use cookies.