Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-inclu...
File: class-wp-image-editor-gd.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress GD Image Editor
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Image_Editor
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* WordPress Image Editor Class for Image Manipulation through GD
[9] Fix | Delete
*
[10] Fix | Delete
* @since 3.5.0
[11] Fix | Delete
*
[12] Fix | Delete
* @see WP_Image_Editor
[13] Fix | Delete
*/
[14] Fix | Delete
class WP_Image_Editor_GD extends WP_Image_Editor {
[15] Fix | Delete
/**
[16] Fix | Delete
* GD Resource.
[17] Fix | Delete
*
[18] Fix | Delete
* @var resource|GdImage
[19] Fix | Delete
*/
[20] Fix | Delete
protected $image;
[21] Fix | Delete
[22] Fix | Delete
public function __destruct() {
[23] Fix | Delete
if ( $this->image ) {
[24] Fix | Delete
// We don't need the original in memory anymore.
[25] Fix | Delete
imagedestroy( $this->image );
[26] Fix | Delete
}
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Checks to see if current environment supports GD.
[31] Fix | Delete
*
[32] Fix | Delete
* @since 3.5.0
[33] Fix | Delete
*
[34] Fix | Delete
* @param array $args
[35] Fix | Delete
* @return bool
[36] Fix | Delete
*/
[37] Fix | Delete
public static function test( $args = array() ) {
[38] Fix | Delete
if ( ! extension_loaded( 'gd' ) || ! function_exists( 'gd_info' ) ) {
[39] Fix | Delete
return false;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
// On some setups GD library does not provide imagerotate() - Ticket #11536.
[43] Fix | Delete
if ( isset( $args['methods'] ) &&
[44] Fix | Delete
in_array( 'rotate', $args['methods'], true ) &&
[45] Fix | Delete
! function_exists( 'imagerotate' ) ) {
[46] Fix | Delete
[47] Fix | Delete
return false;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
return true;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Checks to see if editor supports the mime-type specified.
[55] Fix | Delete
*
[56] Fix | Delete
* @since 3.5.0
[57] Fix | Delete
*
[58] Fix | Delete
* @param string $mime_type
[59] Fix | Delete
* @return bool
[60] Fix | Delete
*/
[61] Fix | Delete
public static function supports_mime_type( $mime_type ) {
[62] Fix | Delete
$image_types = imagetypes();
[63] Fix | Delete
switch ( $mime_type ) {
[64] Fix | Delete
case 'image/jpeg':
[65] Fix | Delete
return ( $image_types & IMG_JPG ) !== 0;
[66] Fix | Delete
case 'image/png':
[67] Fix | Delete
return ( $image_types & IMG_PNG ) !== 0;
[68] Fix | Delete
case 'image/gif':
[69] Fix | Delete
return ( $image_types & IMG_GIF ) !== 0;
[70] Fix | Delete
case 'image/webp':
[71] Fix | Delete
return ( $image_types & IMG_WEBP ) !== 0;
[72] Fix | Delete
case 'image/avif':
[73] Fix | Delete
return ( $image_types & IMG_AVIF ) !== 0 && function_exists( 'imageavif' );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
return false;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Loads image from $this->file into new GD Resource.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 3.5.0
[83] Fix | Delete
*
[84] Fix | Delete
* @return true|WP_Error True if loaded successfully; WP_Error on failure.
[85] Fix | Delete
*/
[86] Fix | Delete
public function load() {
[87] Fix | Delete
if ( $this->image ) {
[88] Fix | Delete
return true;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) {
[92] Fix | Delete
return new WP_Error( 'error_loading_image', __( 'File does not exist?' ), $this->file );
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
// Set artificially high because GD uses uncompressed images in memory.
[96] Fix | Delete
wp_raise_memory_limit( 'image' );
[97] Fix | Delete
[98] Fix | Delete
$file_contents = @file_get_contents( $this->file );
[99] Fix | Delete
[100] Fix | Delete
if ( ! $file_contents ) {
[101] Fix | Delete
return new WP_Error( 'error_loading_image', __( 'File does not exist?' ), $this->file );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// WebP may not work with imagecreatefromstring().
[105] Fix | Delete
if (
[106] Fix | Delete
function_exists( 'imagecreatefromwebp' ) &&
[107] Fix | Delete
( 'image/webp' === wp_get_image_mime( $this->file ) )
[108] Fix | Delete
) {
[109] Fix | Delete
$this->image = @imagecreatefromwebp( $this->file );
[110] Fix | Delete
} else {
[111] Fix | Delete
$this->image = @imagecreatefromstring( $file_contents );
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
// AVIF may not work with imagecreatefromstring().
[115] Fix | Delete
if (
[116] Fix | Delete
function_exists( 'imagecreatefromavif' ) &&
[117] Fix | Delete
( 'image/avif' === wp_get_image_mime( $this->file ) )
[118] Fix | Delete
) {
[119] Fix | Delete
$this->image = @imagecreatefromavif( $this->file );
[120] Fix | Delete
} else {
[121] Fix | Delete
$this->image = @imagecreatefromstring( $file_contents );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if ( ! is_gd_image( $this->image ) ) {
[125] Fix | Delete
return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$size = wp_getimagesize( $this->file );
[129] Fix | Delete
[130] Fix | Delete
if ( ! $size ) {
[131] Fix | Delete
return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file );
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
[135] Fix | Delete
imagealphablending( $this->image, false );
[136] Fix | Delete
imagesavealpha( $this->image, true );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
$this->update_size( $size[0], $size[1] );
[140] Fix | Delete
$this->mime_type = $size['mime'];
[141] Fix | Delete
[142] Fix | Delete
return $this->set_quality();
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Sets or updates current image size.
[147] Fix | Delete
*
[148] Fix | Delete
* @since 3.5.0
[149] Fix | Delete
*
[150] Fix | Delete
* @param int $width
[151] Fix | Delete
* @param int $height
[152] Fix | Delete
* @return true
[153] Fix | Delete
*/
[154] Fix | Delete
protected function update_size( $width = false, $height = false ) {
[155] Fix | Delete
if ( ! $width ) {
[156] Fix | Delete
$width = imagesx( $this->image );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
if ( ! $height ) {
[160] Fix | Delete
$height = imagesy( $this->image );
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
return parent::update_size( $width, $height );
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Resizes current image.
[168] Fix | Delete
*
[169] Fix | Delete
* Wraps `::_resize()` which returns a GD resource or GdImage instance.
[170] Fix | Delete
*
[171] Fix | Delete
* At minimum, either a height or width must be provided. If one of the two is set
[172] Fix | Delete
* to null, the resize will maintain aspect ratio according to the provided dimension.
[173] Fix | Delete
*
[174] Fix | Delete
* @since 3.5.0
[175] Fix | Delete
*
[176] Fix | Delete
* @param int|null $max_w Image width.
[177] Fix | Delete
* @param int|null $max_h Image height.
[178] Fix | Delete
* @param bool|array $crop {
[179] Fix | Delete
* Optional. Image cropping behavior. If false, the image will be scaled (default).
[180] Fix | Delete
* If true, image will be cropped to the specified dimensions using center positions.
[181] Fix | Delete
* If an array, the image will be cropped using the array to specify the crop location:
[182] Fix | Delete
*
[183] Fix | Delete
* @type string $0 The x crop position. Accepts 'left' 'center', or 'right'.
[184] Fix | Delete
* @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
[185] Fix | Delete
* }
[186] Fix | Delete
* @return true|WP_Error
[187] Fix | Delete
*/
[188] Fix | Delete
public function resize( $max_w, $max_h, $crop = false ) {
[189] Fix | Delete
if ( ( $this->size['width'] === $max_w ) && ( $this->size['height'] === $max_h ) ) {
[190] Fix | Delete
return true;
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
$resized = $this->_resize( $max_w, $max_h, $crop );
[194] Fix | Delete
[195] Fix | Delete
if ( is_gd_image( $resized ) ) {
[196] Fix | Delete
imagedestroy( $this->image );
[197] Fix | Delete
$this->image = $resized;
[198] Fix | Delete
return true;
[199] Fix | Delete
[200] Fix | Delete
} elseif ( is_wp_error( $resized ) ) {
[201] Fix | Delete
return $resized;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ), $this->file );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* @param int $max_w
[209] Fix | Delete
* @param int $max_h
[210] Fix | Delete
* @param bool|array $crop {
[211] Fix | Delete
* Optional. Image cropping behavior. If false, the image will be scaled (default).
[212] Fix | Delete
* If true, image will be cropped to the specified dimensions using center positions.
[213] Fix | Delete
* If an array, the image will be cropped using the array to specify the crop location:
[214] Fix | Delete
*
[215] Fix | Delete
* @type string $0 The x crop position. Accepts 'left' 'center', or 'right'.
[216] Fix | Delete
* @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
[217] Fix | Delete
* }
[218] Fix | Delete
* @return resource|GdImage|WP_Error
[219] Fix | Delete
*/
[220] Fix | Delete
protected function _resize( $max_w, $max_h, $crop = false ) {
[221] Fix | Delete
$dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop );
[222] Fix | Delete
[223] Fix | Delete
if ( ! $dims ) {
[224] Fix | Delete
return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ), $this->file );
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
[228] Fix | Delete
[229] Fix | Delete
$resized = wp_imagecreatetruecolor( $dst_w, $dst_h );
[230] Fix | Delete
imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
[231] Fix | Delete
[232] Fix | Delete
if ( is_gd_image( $resized ) ) {
[233] Fix | Delete
$this->update_size( $dst_w, $dst_h );
[234] Fix | Delete
return $resized;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ), $this->file );
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Create multiple smaller images from a single source.
[242] Fix | Delete
*
[243] Fix | Delete
* Attempts to create all sub-sizes and returns the meta data at the end. This
[244] Fix | Delete
* may result in the server running out of resources. When it fails there may be few
[245] Fix | Delete
* "orphaned" images left over as the meta data is never returned and saved.
[246] Fix | Delete
*
[247] Fix | Delete
* As of 5.3.0 the preferred way to do this is with `make_subsize()`. It creates
[248] Fix | Delete
* the new images one at a time and allows for the meta data to be saved after
[249] Fix | Delete
* each new image is created.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 3.5.0
[252] Fix | Delete
*
[253] Fix | Delete
* @param array $sizes {
[254] Fix | Delete
* An array of image size data arrays.
[255] Fix | Delete
*
[256] Fix | Delete
* Either a height or width must be provided.
[257] Fix | Delete
* If one of the two is set to null, the resize will
[258] Fix | Delete
* maintain aspect ratio according to the source image.
[259] Fix | Delete
*
[260] Fix | Delete
* @type array ...$0 {
[261] Fix | Delete
* Array of height, width values, and whether to crop.
[262] Fix | Delete
*
[263] Fix | Delete
* @type int $width Image width. Optional if `$height` is specified.
[264] Fix | Delete
* @type int $height Image height. Optional if `$width` is specified.
[265] Fix | Delete
* @type bool|array $crop Optional. Whether to crop the image. Default false.
[266] Fix | Delete
* }
[267] Fix | Delete
* }
[268] Fix | Delete
* @return array An array of resized images' metadata by size.
[269] Fix | Delete
*/
[270] Fix | Delete
public function multi_resize( $sizes ) {
[271] Fix | Delete
$metadata = array();
[272] Fix | Delete
[273] Fix | Delete
foreach ( $sizes as $size => $size_data ) {
[274] Fix | Delete
$meta = $this->make_subsize( $size_data );
[275] Fix | Delete
[276] Fix | Delete
if ( ! is_wp_error( $meta ) ) {
[277] Fix | Delete
$metadata[ $size ] = $meta;
[278] Fix | Delete
}
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
return $metadata;
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
/**
[285] Fix | Delete
* Create an image sub-size and return the image meta data value for it.
[286] Fix | Delete
*
[287] Fix | Delete
* @since 5.3.0
[288] Fix | Delete
*
[289] Fix | Delete
* @param array $size_data {
[290] Fix | Delete
* Array of size data.
[291] Fix | Delete
*
[292] Fix | Delete
* @type int $width The maximum width in pixels.
[293] Fix | Delete
* @type int $height The maximum height in pixels.
[294] Fix | Delete
* @type bool|array $crop Whether to crop the image to exact dimensions.
[295] Fix | Delete
* }
[296] Fix | Delete
* @return array|WP_Error The image data array for inclusion in the `sizes` array in the image meta,
[297] Fix | Delete
* WP_Error object on error.
[298] Fix | Delete
*/
[299] Fix | Delete
public function make_subsize( $size_data ) {
[300] Fix | Delete
if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
[301] Fix | Delete
return new WP_Error( 'image_subsize_create_error', __( 'Cannot resize the image. Both width and height are not set.' ) );
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
$orig_size = $this->size;
[305] Fix | Delete
[306] Fix | Delete
if ( ! isset( $size_data['width'] ) ) {
[307] Fix | Delete
$size_data['width'] = null;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
if ( ! isset( $size_data['height'] ) ) {
[311] Fix | Delete
$size_data['height'] = null;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
if ( ! isset( $size_data['crop'] ) ) {
[315] Fix | Delete
$size_data['crop'] = false;
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
$resized = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
[319] Fix | Delete
[320] Fix | Delete
if ( is_wp_error( $resized ) ) {
[321] Fix | Delete
$saved = $resized;
[322] Fix | Delete
} else {
[323] Fix | Delete
$saved = $this->_save( $resized );
[324] Fix | Delete
imagedestroy( $resized );
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
$this->size = $orig_size;
[328] Fix | Delete
[329] Fix | Delete
if ( ! is_wp_error( $saved ) ) {
[330] Fix | Delete
unset( $saved['path'] );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
return $saved;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
/**
[337] Fix | Delete
* Crops Image.
[338] Fix | Delete
*
[339] Fix | Delete
* @since 3.5.0
[340] Fix | Delete
*
[341] Fix | Delete
* @param int $src_x The start x position to crop from.
[342] Fix | Delete
* @param int $src_y The start y position to crop from.
[343] Fix | Delete
* @param int $src_w The width to crop.
[344] Fix | Delete
* @param int $src_h The height to crop.
[345] Fix | Delete
* @param int $dst_w Optional. The destination width.
[346] Fix | Delete
* @param int $dst_h Optional. The destination height.
[347] Fix | Delete
* @param bool $src_abs Optional. If the source crop points are absolute.
[348] Fix | Delete
* @return true|WP_Error
[349] Fix | Delete
*/
[350] Fix | Delete
public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
[351] Fix | Delete
/*
[352] Fix | Delete
* If destination width/height isn't specified,
[353] Fix | Delete
* use same as width/height from source.
[354] Fix | Delete
*/
[355] Fix | Delete
if ( ! $dst_w ) {
[356] Fix | Delete
$dst_w = $src_w;
[357] Fix | Delete
}
[358] Fix | Delete
if ( ! $dst_h ) {
[359] Fix | Delete
$dst_h = $src_h;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
foreach ( array( $src_w, $src_h, $dst_w, $dst_h ) as $value ) {
[363] Fix | Delete
if ( ! is_numeric( $value ) || (int) $value <= 0 ) {
[364] Fix | Delete
return new WP_Error( 'image_crop_error', __( 'Image crop failed.' ), $this->file );
[365] Fix | Delete
}
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
$dst = wp_imagecreatetruecolor( (int) $dst_w, (int) $dst_h );
[369] Fix | Delete
[370] Fix | Delete
if ( $src_abs ) {
[371] Fix | Delete
$src_w -= $src_x;
[372] Fix | Delete
$src_h -= $src_y;
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
if ( function_exists( 'imageantialias' ) ) {
[376] Fix | Delete
imageantialias( $dst, true );
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
imagecopyresampled( $dst, $this->image, 0, 0, (int) $src_x, (int) $src_y, (int) $dst_w, (int) $dst_h, (int) $src_w, (int) $src_h );
[380] Fix | Delete
[381] Fix | Delete
if ( is_gd_image( $dst ) ) {
[382] Fix | Delete
imagedestroy( $this->image );
[383] Fix | Delete
$this->image = $dst;
[384] Fix | Delete
$this->update_size();
[385] Fix | Delete
return true;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
return new WP_Error( 'image_crop_error', __( 'Image crop failed.' ), $this->file );
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* Rotates current image counter-clockwise by $angle.
[393] Fix | Delete
* Ported from image-edit.php
[394] Fix | Delete
*
[395] Fix | Delete
* @since 3.5.0
[396] Fix | Delete
*
[397] Fix | Delete
* @param float $angle
[398] Fix | Delete
* @return true|WP_Error
[399] Fix | Delete
*/
[400] Fix | Delete
public function rotate( $angle ) {
[401] Fix | Delete
if ( function_exists( 'imagerotate' ) ) {
[402] Fix | Delete
$transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 );
[403] Fix | Delete
$rotated = imagerotate( $this->image, $angle, $transparency );
[404] Fix | Delete
[405] Fix | Delete
if ( is_gd_image( $rotated ) ) {
[406] Fix | Delete
imagealphablending( $rotated, true );
[407] Fix | Delete
imagesavealpha( $rotated, true );
[408] Fix | Delete
imagedestroy( $this->image );
[409] Fix | Delete
$this->image = $rotated;
[410] Fix | Delete
$this->update_size();
[411] Fix | Delete
return true;
[412] Fix | Delete
}
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
return new WP_Error( 'image_rotate_error', __( 'Image rotate failed.' ), $this->file );
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Flips current image.
[420] Fix | Delete
*
[421] Fix | Delete
* @since 3.5.0
[422] Fix | Delete
*
[423] Fix | Delete
* @param bool $horz Flip along Horizontal Axis.
[424] Fix | Delete
* @param bool $vert Flip along Vertical Axis.
[425] Fix | Delete
* @return true|WP_Error
[426] Fix | Delete
*/
[427] Fix | Delete
public function flip( $horz, $vert ) {
[428] Fix | Delete
$w = $this->size['width'];
[429] Fix | Delete
$h = $this->size['height'];
[430] Fix | Delete
$dst = wp_imagecreatetruecolor( $w, $h );
[431] Fix | Delete
[432] Fix | Delete
if ( is_gd_image( $dst ) ) {
[433] Fix | Delete
$sx = $vert ? ( $w - 1 ) : 0;
[434] Fix | Delete
$sy = $horz ? ( $h - 1 ) : 0;
[435] Fix | Delete
$sw = $vert ? -$w : $w;
[436] Fix | Delete
$sh = $horz ? -$h : $h;
[437] Fix | Delete
[438] Fix | Delete
if ( imagecopyresampled( $dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) {
[439] Fix | Delete
imagedestroy( $this->image );
[440] Fix | Delete
$this->image = $dst;
[441] Fix | Delete
return true;
[442] Fix | Delete
}
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
return new WP_Error( 'image_flip_error', __( 'Image flip failed.' ), $this->file );
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
/**
[449] Fix | Delete
* Saves current in-memory image to file.
[450] Fix | Delete
*
[451] Fix | Delete
* @since 3.5.0
[452] Fix | Delete
* @since 5.9.0 Renamed `$filename` to `$destfilename` to match parent class
[453] Fix | Delete
* for PHP 8 named parameter support.
[454] Fix | Delete
* @since 6.0.0 The `$filesize` value was added to the returned array.
[455] Fix | Delete
*
[456] Fix | Delete
* @param string|null $destfilename Optional. Destination filename. Default null.
[457] Fix | Delete
* @param string|null $mime_type Optional. The mime-type. Default null.
[458] Fix | Delete
* @return array|WP_Error {
[459] Fix | Delete
* Array on success or WP_Error if the file failed to save.
[460] Fix | Delete
*
[461] Fix | Delete
* @type string $path Path to the image file.
[462] Fix | Delete
* @type string $file Name of the image file.
[463] Fix | Delete
* @type int $width Image width.
[464] Fix | Delete
* @type int $height Image height.
[465] Fix | Delete
* @type string $mime-type The mime type of the image.
[466] Fix | Delete
* @type int $filesize File size of the image.
[467] Fix | Delete
* }
[468] Fix | Delete
*/
[469] Fix | Delete
public function save( $destfilename = null, $mime_type = null ) {
[470] Fix | Delete
$saved = $this->_save( $this->image, $destfilename, $mime_type );
[471] Fix | Delete
[472] Fix | Delete
if ( ! is_wp_error( $saved ) ) {
[473] Fix | Delete
$this->file = $saved['path'];
[474] Fix | Delete
$this->mime_type = $saved['mime-type'];
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
return $saved;
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
/**
[481] Fix | Delete
* @since 3.5.0
[482] Fix | Delete
* @since 6.0.0 The `$filesize` value was added to the returned array.
[483] Fix | Delete
*
[484] Fix | Delete
* @param resource|GdImage $image
[485] Fix | Delete
* @param string|null $filename
[486] Fix | Delete
* @param string|null $mime_type
[487] Fix | Delete
* @return array|WP_Error {
[488] Fix | Delete
* Array on success or WP_Error if the file failed to save.
[489] Fix | Delete
*
[490] Fix | Delete
* @type string $path Path to the image file.
[491] Fix | Delete
* @type string $file Name of the image file.
[492] Fix | Delete
* @type int $width Image width.
[493] Fix | Delete
* @type int $height Image height.
[494] Fix | Delete
* @type string $mime-type The mime type of the image.
[495] Fix | Delete
* @type int $filesize File size of the image.
[496] Fix | Delete
* }
[497] Fix | Delete
*/
[498] Fix | Delete
protected function _save( $image, $filename = null, $mime_type = null ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function