Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: class-wp-image-editor.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Base WordPress 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
* Base image editor class from which implementations extend
[9] Fix | Delete
*
[10] Fix | Delete
* @since 3.5.0
[11] Fix | Delete
*/
[12] Fix | Delete
#[AllowDynamicProperties]
[13] Fix | Delete
abstract class WP_Image_Editor {
[14] Fix | Delete
protected $file = null;
[15] Fix | Delete
protected $size = null;
[16] Fix | Delete
protected $mime_type = null;
[17] Fix | Delete
protected $output_mime_type = null;
[18] Fix | Delete
protected $default_mime_type = 'image/jpeg';
[19] Fix | Delete
protected $quality = false;
[20] Fix | Delete
[21] Fix | Delete
// Deprecated since 5.8.1. See get_default_quality() below.
[22] Fix | Delete
protected $default_quality = 82;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Each instance handles a single file.
[26] Fix | Delete
*
[27] Fix | Delete
* @param string $file Path to the file to load.
[28] Fix | Delete
*/
[29] Fix | Delete
public function __construct( $file ) {
[30] Fix | Delete
$this->file = $file;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Checks to see if current environment supports the editor chosen.
[35] Fix | Delete
* Must be overridden in a subclass.
[36] Fix | Delete
*
[37] Fix | Delete
* @since 3.5.0
[38] Fix | Delete
*
[39] Fix | Delete
* @abstract
[40] Fix | Delete
*
[41] Fix | Delete
* @param array $args
[42] Fix | Delete
* @return bool
[43] Fix | Delete
*/
[44] Fix | Delete
public static function test( $args = array() ) {
[45] Fix | Delete
return false;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Checks to see if editor supports the mime-type specified.
[50] Fix | Delete
* Must be overridden in a subclass.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 3.5.0
[53] Fix | Delete
*
[54] Fix | Delete
* @abstract
[55] Fix | Delete
*
[56] Fix | Delete
* @param string $mime_type
[57] Fix | Delete
* @return bool
[58] Fix | Delete
*/
[59] Fix | Delete
public static function supports_mime_type( $mime_type ) {
[60] Fix | Delete
return false;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Loads image from $this->file into editor.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 3.5.0
[67] Fix | Delete
* @abstract
[68] Fix | Delete
*
[69] Fix | Delete
* @return true|WP_Error True if loaded; WP_Error on failure.
[70] Fix | Delete
*/
[71] Fix | Delete
abstract public function load();
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Saves current image to file.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 3.5.0
[77] Fix | Delete
* @since 6.0.0 The `$filesize` value was added to the returned array.
[78] Fix | Delete
* @abstract
[79] Fix | Delete
*
[80] Fix | Delete
* @param string $destfilename Optional. Destination filename. Default null.
[81] Fix | Delete
* @param string $mime_type Optional. The mime-type. Default null.
[82] Fix | Delete
* @return array|WP_Error {
[83] Fix | Delete
* Array on success or WP_Error if the file failed to save.
[84] Fix | Delete
*
[85] Fix | Delete
* @type string $path Path to the image file.
[86] Fix | Delete
* @type string $file Name of the image file.
[87] Fix | Delete
* @type int $width Image width.
[88] Fix | Delete
* @type int $height Image height.
[89] Fix | Delete
* @type string $mime-type The mime type of the image.
[90] Fix | Delete
* @type int $filesize File size of the image.
[91] Fix | Delete
* }
[92] Fix | Delete
*/
[93] Fix | Delete
abstract public function save( $destfilename = null, $mime_type = null );
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Resizes current image.
[97] Fix | Delete
*
[98] Fix | Delete
* At minimum, either a height or width must be provided.
[99] Fix | Delete
* If one of the two is set to null, the resize will
[100] Fix | Delete
* maintain aspect ratio according to the provided dimension.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 3.5.0
[103] Fix | Delete
* @abstract
[104] Fix | Delete
*
[105] Fix | Delete
* @param int|null $max_w Image width.
[106] Fix | Delete
* @param int|null $max_h Image height.
[107] Fix | Delete
* @param bool|array $crop {
[108] Fix | Delete
* Optional. Image cropping behavior. If false, the image will be scaled (default).
[109] Fix | Delete
* If true, image will be cropped to the specified dimensions using center positions.
[110] Fix | Delete
* If an array, the image will be cropped using the array to specify the crop location:
[111] Fix | Delete
*
[112] Fix | Delete
* @type string $0 The x crop position. Accepts 'left', 'center', or 'right'.
[113] Fix | Delete
* @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
[114] Fix | Delete
* }
[115] Fix | Delete
* @return true|WP_Error
[116] Fix | Delete
*/
[117] Fix | Delete
abstract public function resize( $max_w, $max_h, $crop = false );
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Resize multiple images from a single source.
[121] Fix | Delete
*
[122] Fix | Delete
* @since 3.5.0
[123] Fix | Delete
* @abstract
[124] Fix | Delete
*
[125] Fix | Delete
* @param array $sizes {
[126] Fix | Delete
* An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
[127] Fix | Delete
*
[128] Fix | Delete
* @type array ...$0 {
[129] Fix | Delete
* @type int $width Image width.
[130] Fix | Delete
* @type int $height Image height.
[131] Fix | Delete
* @type bool|array $crop Optional. Whether to crop the image. Default false.
[132] Fix | Delete
* }
[133] Fix | Delete
* }
[134] Fix | Delete
* @return array An array of resized images metadata by size.
[135] Fix | Delete
*/
[136] Fix | Delete
abstract public function multi_resize( $sizes );
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Crops Image.
[140] Fix | Delete
*
[141] Fix | Delete
* @since 3.5.0
[142] Fix | Delete
* @abstract
[143] Fix | Delete
*
[144] Fix | Delete
* @param int $src_x The start x position to crop from.
[145] Fix | Delete
* @param int $src_y The start y position to crop from.
[146] Fix | Delete
* @param int $src_w The width to crop.
[147] Fix | Delete
* @param int $src_h The height to crop.
[148] Fix | Delete
* @param int $dst_w Optional. The destination width.
[149] Fix | Delete
* @param int $dst_h Optional. The destination height.
[150] Fix | Delete
* @param bool $src_abs Optional. If the source crop points are absolute.
[151] Fix | Delete
* @return true|WP_Error
[152] Fix | Delete
*/
[153] Fix | Delete
abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false );
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Rotates current image counter-clockwise by $angle.
[157] Fix | Delete
*
[158] Fix | Delete
* @since 3.5.0
[159] Fix | Delete
* @abstract
[160] Fix | Delete
*
[161] Fix | Delete
* @param float $angle
[162] Fix | Delete
* @return true|WP_Error
[163] Fix | Delete
*/
[164] Fix | Delete
abstract public function rotate( $angle );
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Flips current image.
[168] Fix | Delete
*
[169] Fix | Delete
* @since 3.5.0
[170] Fix | Delete
* @abstract
[171] Fix | Delete
*
[172] Fix | Delete
* @param bool $horz Flip along Horizontal Axis
[173] Fix | Delete
* @param bool $vert Flip along Vertical Axis
[174] Fix | Delete
* @return true|WP_Error
[175] Fix | Delete
*/
[176] Fix | Delete
abstract public function flip( $horz, $vert );
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* Streams current image to browser.
[180] Fix | Delete
*
[181] Fix | Delete
* @since 3.5.0
[182] Fix | Delete
* @abstract
[183] Fix | Delete
*
[184] Fix | Delete
* @param string $mime_type The mime type of the image.
[185] Fix | Delete
* @return true|WP_Error True on success, WP_Error object on failure.
[186] Fix | Delete
*/
[187] Fix | Delete
abstract public function stream( $mime_type = null );
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Gets dimensions of image.
[191] Fix | Delete
*
[192] Fix | Delete
* @since 3.5.0
[193] Fix | Delete
*
[194] Fix | Delete
* @return int[] {
[195] Fix | Delete
* Dimensions of the image.
[196] Fix | Delete
*
[197] Fix | Delete
* @type int $width The image width.
[198] Fix | Delete
* @type int $height The image height.
[199] Fix | Delete
* }
[200] Fix | Delete
*/
[201] Fix | Delete
public function get_size() {
[202] Fix | Delete
return $this->size;
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* Sets current image size.
[207] Fix | Delete
*
[208] Fix | Delete
* @since 3.5.0
[209] Fix | Delete
*
[210] Fix | Delete
* @param int $width
[211] Fix | Delete
* @param int $height
[212] Fix | Delete
* @return true
[213] Fix | Delete
*/
[214] Fix | Delete
protected function update_size( $width = null, $height = null ) {
[215] Fix | Delete
$this->size = array(
[216] Fix | Delete
'width' => (int) $width,
[217] Fix | Delete
'height' => (int) $height,
[218] Fix | Delete
);
[219] Fix | Delete
return true;
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Gets the Image Compression quality on a 1-100% scale.
[224] Fix | Delete
*
[225] Fix | Delete
* @since 4.0.0
[226] Fix | Delete
*
[227] Fix | Delete
* @return int Compression Quality. Range: [1,100]
[228] Fix | Delete
*/
[229] Fix | Delete
public function get_quality() {
[230] Fix | Delete
if ( ! $this->quality ) {
[231] Fix | Delete
$this->set_quality();
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
return $this->quality;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Sets Image Compression quality on a 1-100% scale.
[239] Fix | Delete
*
[240] Fix | Delete
* @since 3.5.0
[241] Fix | Delete
* @since 6.8.0 The `$dims` parameter was added.
[242] Fix | Delete
*
[243] Fix | Delete
* @param int $quality Compression Quality. Range: [1,100]
[244] Fix | Delete
* @param array $dims Optional. Image dimensions array with 'width' and 'height' keys.
[245] Fix | Delete
* @return true|WP_Error True if set successfully; WP_Error on failure.
[246] Fix | Delete
[247] Fix | Delete
*/
[248] Fix | Delete
public function set_quality( $quality = null, $dims = array() ) {
[249] Fix | Delete
// Use the output mime type if present. If not, fall back to the input/initial mime type.
[250] Fix | Delete
$mime_type = ! empty( $this->output_mime_type ) ? $this->output_mime_type : $this->mime_type;
[251] Fix | Delete
// Get the default quality setting for the mime type.
[252] Fix | Delete
$default_quality = $this->get_default_quality( $mime_type );
[253] Fix | Delete
[254] Fix | Delete
if ( null === $quality ) {
[255] Fix | Delete
/**
[256] Fix | Delete
* Filters the default image compression quality setting.
[257] Fix | Delete
*
[258] Fix | Delete
* Applies only during initial editor instantiation, or when set_quality() is run
[259] Fix | Delete
* manually without the `$quality` argument.
[260] Fix | Delete
*
[261] Fix | Delete
* The WP_Image_Editor::set_quality() method has priority over the filter.
[262] Fix | Delete
*
[263] Fix | Delete
* @since 3.5.0
[264] Fix | Delete
* @since 6.8.0 Added the size parameter.
[265] Fix | Delete
*
[266] Fix | Delete
* @param int $quality Quality level between 1 (low) and 100 (high).
[267] Fix | Delete
* @param string $mime_type Image mime type.
[268] Fix | Delete
* @param array $size {
[269] Fix | Delete
* Dimensions of the image.
[270] Fix | Delete
*
[271] Fix | Delete
* @type int $width The image width.
[272] Fix | Delete
* @type int $height The image height.
[273] Fix | Delete
* }
[274] Fix | Delete
*/
[275] Fix | Delete
$quality = apply_filters( 'wp_editor_set_quality', $default_quality, $mime_type, $dims ? $dims : $this->size );
[276] Fix | Delete
[277] Fix | Delete
if ( 'image/jpeg' === $mime_type ) {
[278] Fix | Delete
/**
[279] Fix | Delete
* Filters the JPEG compression quality for backward-compatibility.
[280] Fix | Delete
*
[281] Fix | Delete
* Applies only during initial editor instantiation, or when set_quality() is run
[282] Fix | Delete
* manually without the `$quality` argument.
[283] Fix | Delete
*
[284] Fix | Delete
* The WP_Image_Editor::set_quality() method has priority over the filter.
[285] Fix | Delete
*
[286] Fix | Delete
* The filter is evaluated under two contexts: 'image_resize', and 'edit_image',
[287] Fix | Delete
* (when a JPEG image is saved to file).
[288] Fix | Delete
*
[289] Fix | Delete
* @since 2.5.0
[290] Fix | Delete
*
[291] Fix | Delete
* @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG.
[292] Fix | Delete
* @param string $context Context of the filter.
[293] Fix | Delete
*/
[294] Fix | Delete
$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
if ( $quality < 0 || $quality > 100 ) {
[298] Fix | Delete
$quality = $default_quality;
[299] Fix | Delete
}
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
// Allow 0, but squash to 1 due to identical images in GD, and for backward compatibility.
[303] Fix | Delete
if ( 0 === $quality ) {
[304] Fix | Delete
$quality = 1;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) {
[308] Fix | Delete
$this->quality = $quality;
[309] Fix | Delete
return true;
[310] Fix | Delete
} else {
[311] Fix | Delete
return new WP_Error( 'invalid_image_quality', __( 'Attempted to set image quality outside of the range [1,100].' ) );
[312] Fix | Delete
}
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
/**
[316] Fix | Delete
* Returns the default compression quality setting for the mime type.
[317] Fix | Delete
*
[318] Fix | Delete
* @since 5.8.1
[319] Fix | Delete
*
[320] Fix | Delete
* @param string $mime_type
[321] Fix | Delete
* @return int The default quality setting for the mime type.
[322] Fix | Delete
*/
[323] Fix | Delete
protected function get_default_quality( $mime_type ) {
[324] Fix | Delete
switch ( $mime_type ) {
[325] Fix | Delete
case 'image/webp':
[326] Fix | Delete
$quality = 86;
[327] Fix | Delete
break;
[328] Fix | Delete
case 'image/jpeg':
[329] Fix | Delete
default:
[330] Fix | Delete
$quality = $this->default_quality;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
return $quality;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
/**
[337] Fix | Delete
* Returns preferred mime-type and extension based on provided
[338] Fix | Delete
* file's extension and mime, or current file's extension and mime.
[339] Fix | Delete
*
[340] Fix | Delete
* Will default to $this->default_mime_type if requested is not supported.
[341] Fix | Delete
*
[342] Fix | Delete
* Provides corrected filename only if filename is provided.
[343] Fix | Delete
*
[344] Fix | Delete
* @since 3.5.0
[345] Fix | Delete
*
[346] Fix | Delete
* @param string $filename
[347] Fix | Delete
* @param string $mime_type
[348] Fix | Delete
* @return array { filename|null, extension, mime-type }
[349] Fix | Delete
*/
[350] Fix | Delete
protected function get_output_format( $filename = null, $mime_type = null ) {
[351] Fix | Delete
$new_ext = null;
[352] Fix | Delete
[353] Fix | Delete
// By default, assume specified type takes priority.
[354] Fix | Delete
if ( $mime_type ) {
[355] Fix | Delete
$new_ext = $this->get_extension( $mime_type );
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
if ( $filename ) {
[359] Fix | Delete
$file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
[360] Fix | Delete
$file_mime = $this->get_mime_type( $file_ext );
[361] Fix | Delete
} else {
[362] Fix | Delete
// If no file specified, grab editor's current extension and mime-type.
[363] Fix | Delete
$file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
[364] Fix | Delete
$file_mime = $this->mime_type;
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
/*
[368] Fix | Delete
* Check to see if specified mime-type is the same as type implied by
[369] Fix | Delete
* file extension. If so, prefer extension from file.
[370] Fix | Delete
*/
[371] Fix | Delete
if ( ! $mime_type || ( $file_mime === $mime_type ) ) {
[372] Fix | Delete
$mime_type = $file_mime;
[373] Fix | Delete
$new_ext = $file_ext;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
$output_format = wp_get_image_editor_output_format( $filename, $mime_type );
[377] Fix | Delete
[378] Fix | Delete
if ( isset( $output_format[ $mime_type ] )
[379] Fix | Delete
&& $this->supports_mime_type( $output_format[ $mime_type ] )
[380] Fix | Delete
) {
[381] Fix | Delete
$mime_type = $output_format[ $mime_type ];
[382] Fix | Delete
$new_ext = $this->get_extension( $mime_type );
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/*
[386] Fix | Delete
* Double-check that the mime-type selected is supported by the editor.
[387] Fix | Delete
* If not, choose a default instead.
[388] Fix | Delete
*/
[389] Fix | Delete
if ( ! $this->supports_mime_type( $mime_type ) ) {
[390] Fix | Delete
/**
[391] Fix | Delete
* Filters default mime type prior to getting the file extension.
[392] Fix | Delete
*
[393] Fix | Delete
* @see wp_get_mime_types()
[394] Fix | Delete
*
[395] Fix | Delete
* @since 3.5.0
[396] Fix | Delete
*
[397] Fix | Delete
* @param string $mime_type Mime type string.
[398] Fix | Delete
*/
[399] Fix | Delete
$mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type );
[400] Fix | Delete
$new_ext = $this->get_extension( $mime_type );
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/*
[404] Fix | Delete
* Ensure both $filename and $new_ext are not empty.
[405] Fix | Delete
* $this->get_extension() returns false on error which would effectively remove the extension
[406] Fix | Delete
* from $filename. That shouldn't happen, files without extensions are not supported.
[407] Fix | Delete
*/
[408] Fix | Delete
if ( $filename && $new_ext ) {
[409] Fix | Delete
$dir = pathinfo( $filename, PATHINFO_DIRNAME );
[410] Fix | Delete
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
[411] Fix | Delete
[412] Fix | Delete
$filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
if ( $mime_type && ( $mime_type !== $this->mime_type ) ) {
[416] Fix | Delete
// The image will be converted when saving. Set the quality for the new mime-type if not already set.
[417] Fix | Delete
if ( $mime_type !== $this->output_mime_type ) {
[418] Fix | Delete
$this->output_mime_type = $mime_type;
[419] Fix | Delete
}
[420] Fix | Delete
$this->set_quality();
[421] Fix | Delete
} elseif ( ! empty( $this->output_mime_type ) ) {
[422] Fix | Delete
// Reset output_mime_type and quality.
[423] Fix | Delete
$this->output_mime_type = null;
[424] Fix | Delete
$this->set_quality();
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
return array( $filename, $new_ext, $mime_type );
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Builds an output filename based on current file, and adding proper suffix
[432] Fix | Delete
*
[433] Fix | Delete
* @since 3.5.0
[434] Fix | Delete
* @since 6.8.0 Passing an empty string as $suffix will now omit the suffix from the generated filename.
[435] Fix | Delete
*
[436] Fix | Delete
* @param string $suffix
[437] Fix | Delete
* @param string $dest_path
[438] Fix | Delete
* @param string $extension
[439] Fix | Delete
* @return string filename
[440] Fix | Delete
*/
[441] Fix | Delete
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
[442] Fix | Delete
// If not empty the $suffix will be appended to the destination filename, just before the extension.
[443] Fix | Delete
if ( $suffix ) {
[444] Fix | Delete
$suffix = '-' . $suffix;
[445] Fix | Delete
} elseif ( '' !== $suffix ) {
[446] Fix | Delete
$suffix = '-' . $this->get_suffix();
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
[450] Fix | Delete
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
[451] Fix | Delete
[452] Fix | Delete
$name = wp_basename( $this->file, ".$ext" );
[453] Fix | Delete
$new_ext = strtolower( $extension ? $extension : $ext );
[454] Fix | Delete
[455] Fix | Delete
if ( ! is_null( $dest_path ) ) {
[456] Fix | Delete
if ( ! wp_is_stream( $dest_path ) ) {
[457] Fix | Delete
$_dest_path = realpath( $dest_path );
[458] Fix | Delete
if ( $_dest_path ) {
[459] Fix | Delete
$dir = $_dest_path;
[460] Fix | Delete
}
[461] Fix | Delete
} else {
[462] Fix | Delete
$dir = $dest_path;
[463] Fix | Delete
}
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}";
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
/**
[470] Fix | Delete
* Builds and returns proper suffix for file based on height and width.
[471] Fix | Delete
*
[472] Fix | Delete
* @since 3.5.0
[473] Fix | Delete
*
[474] Fix | Delete
* @return string|false suffix
[475] Fix | Delete
*/
[476] Fix | Delete
public function get_suffix() {
[477] Fix | Delete
if ( ! $this->get_size() ) {
[478] Fix | Delete
return false;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
return "{$this->size['width']}x{$this->size['height']}";
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
/**
[485] Fix | Delete
* Check if a JPEG image has EXIF Orientation tag and rotate it if needed.
[486] Fix | Delete
*
[487] Fix | Delete
* @since 5.3.0
[488] Fix | Delete
*
[489] Fix | Delete
* @return bool|WP_Error True if the image was rotated. False if not rotated (no EXIF data or the image doesn't need to be rotated).
[490] Fix | Delete
* WP_Error if error while rotating.
[491] Fix | Delete
*/
[492] Fix | Delete
public function maybe_exif_rotate() {
[493] Fix | Delete
$orientation = null;
[494] Fix | Delete
[495] Fix | Delete
if ( is_callable( 'exif_read_data' ) && 'image/jpeg' === $this->mime_type ) {
[496] Fix | Delete
$exif_data = @exif_read_data( $this->file );
[497] Fix | Delete
[498] Fix | Delete
if ( ! empty( $exif_data['Orientation'] ) ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function