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.../httpdocs/wp-conte.../plugins/themify-.../themify
File: img.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Routines for generation of custom image sizes and deletion of these sizes.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 1.9.0
[4] Fix | Delete
* @package themify
[5] Fix | Delete
*/
[6] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
[7] Fix | Delete
[8] Fix | Delete
if ( ! function_exists( 'themify_do_img' ) ) {
[9] Fix | Delete
/**
[10] Fix | Delete
* Resize images dynamically using wp built in functions
[11] Fix | Delete
*
[12] Fix | Delete
* @param string|int $image Image URL or an attachment ID
[13] Fix | Delete
* @param int $width
[14] Fix | Delete
* @param int $height
[15] Fix | Delete
* @param bool $crop
[16] Fix | Delete
* @return array
[17] Fix | Delete
*/
[18] Fix | Delete
function themify_do_img( $image, $width, $height,bool $crop = false ):array {
[19] Fix | Delete
$attachment_id =$img_url= null;
[20] Fix | Delete
if(!is_numeric( $width ) ){
[21] Fix | Delete
$width='';
[22] Fix | Delete
}
[23] Fix | Delete
if(!is_numeric( $height ) ){
[24] Fix | Delete
$height='';
[25] Fix | Delete
}
[26] Fix | Delete
// if an attachment ID has been sent
[27] Fix | Delete
if( is_numeric( $image ) ) {
[28] Fix | Delete
$post = get_post( $image );
[29] Fix | Delete
if( $post ) {
[30] Fix | Delete
$attachment_id = $post->ID;
[31] Fix | Delete
$img_url = wp_get_attachment_url( $attachment_id );
[32] Fix | Delete
}
[33] Fix | Delete
unset($post);
[34] Fix | Delete
} else {
[35] Fix | Delete
if(strpos($image,'data:image/' )!==false ){
[36] Fix | Delete
return array(
[37] Fix | Delete
'url' =>$image,
[38] Fix | Delete
'width' => $width,
[39] Fix | Delete
'height' => $height
[40] Fix | Delete
);
[41] Fix | Delete
}
[42] Fix | Delete
// URL has been passed to the function
[43] Fix | Delete
$img_url = esc_url( $image );
[44] Fix | Delete
[45] Fix | Delete
// Check if the image is an attachment. If it's external return url, width and height.
[46] Fix | Delete
if(strpos($img_url,themify_upload_dir('baseurl'))===false){
[47] Fix | Delete
if($width==='' || $height===''){
[48] Fix | Delete
$size = themify_get_image_size($img_url);
[49] Fix | Delete
if($size!==false){
[50] Fix | Delete
if($width===''){
[51] Fix | Delete
$width=$size['w'];
[52] Fix | Delete
}
[53] Fix | Delete
if($height===''){
[54] Fix | Delete
$height=$size['h'];
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
return array(
[59] Fix | Delete
'url' =>$img_url,
[60] Fix | Delete
'width' => $width,
[61] Fix | Delete
'height' => $height
[62] Fix | Delete
);
[63] Fix | Delete
}
[64] Fix | Delete
// Finally, run a custom database query to get the attachment ID from the modified attachment URL
[65] Fix | Delete
$attachment_id = themify_get_attachment_id_from_url( $img_url);
[66] Fix | Delete
}
[67] Fix | Delete
// Fetch attachment metadata. Up to this point we know the attachment ID is valid.
[68] Fix | Delete
$meta = $attachment_id ?wp_get_attachment_metadata( $attachment_id ):null;
[69] Fix | Delete
[70] Fix | Delete
// missing metadata. bail.
[71] Fix | Delete
if (!is_array( $meta )) {
[72] Fix | Delete
if($img_url!==null){
[73] Fix | Delete
$ext=strtolower(strtok(pathinfo($img_url,PATHINFO_EXTENSION ),'?'));
[74] Fix | Delete
if($ext==='png' || $ext==='jpg' || $ext==='jpeg' || $ext==='webp' || $ext==='gif' ||$ext==='bmp' ){//popular types
[75] Fix | Delete
$upload_dir = themify_upload_dir();
[76] Fix | Delete
$attached_file=str_replace($upload_dir['baseurl'],$upload_dir['basedir'],$img_url);
[77] Fix | Delete
if(!is_file ($attached_file)){
[78] Fix | Delete
$attached_file=$attachment_id?get_attached_file( $attachment_id ):null;
[79] Fix | Delete
}
[80] Fix | Delete
if($attached_file){
[81] Fix | Delete
$size=themify_get_image_size($attached_file,true);
[82] Fix | Delete
if($size){
[83] Fix | Delete
$meta=array(
[84] Fix | Delete
'width'=>$size['w'],
[85] Fix | Delete
'height'=>$size['h'],
[86] Fix | Delete
'file'=>trim(str_replace($upload_dir['basedir'],'',$attached_file),'/')
[87] Fix | Delete
);
[88] Fix | Delete
//if the meta doesn't exist it means the image large size also doesn't exist,that is why checking if the image is too large before cropping,otherwise the site will down
[89] Fix | Delete
if($meta['width']>2560 || $meta['height']>2560){
[90] Fix | Delete
return array(
[91] Fix | Delete
'url' => $img_url,
[92] Fix | Delete
'width' => $width,
[93] Fix | Delete
'height' => $height,
[94] Fix | Delete
'is_large'=>true
[95] Fix | Delete
);
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
}
[99] Fix | Delete
unset($upload_dir,$ext,$size,$attached_file);
[100] Fix | Delete
}
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
if ( ! is_array( $meta ) ) {
[104] Fix | Delete
return array(
[105] Fix | Delete
'url' => $img_url,
[106] Fix | Delete
'width' => $width,
[107] Fix | Delete
'height' => $height
[108] Fix | Delete
);
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
// Perform calculations when height or width = 0
[113] Fix | Delete
if( empty( $width ) ) {
[114] Fix | Delete
$width = 0;
[115] Fix | Delete
}
[116] Fix | Delete
if ( empty( $height ) ) {
[117] Fix | Delete
// If width and height or original image are available as metadata
[118] Fix | Delete
if ( !empty( $meta['width'] ) && !empty( $meta['height'] ) ) {
[119] Fix | Delete
// Divide width by original image aspect ratio to obtain projected height
[120] Fix | Delete
// The floor function is used so it returns an int and metadata can be written
[121] Fix | Delete
$height = (int)(floor( $width / ( $meta['width'] / $meta['height'] ) ));
[122] Fix | Delete
} else {
[123] Fix | Delete
$height = 0;
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
// Check if resized image already exists
[127] Fix | Delete
if ( is_array( $meta ) && isset( $meta['sizes']["resized-{$width}x{$height}"] ) ) {
[128] Fix | Delete
$size = $meta['sizes']["resized-{$width}x{$height}"];
[129] Fix | Delete
if( isset( $size['width'],$size['height'] )) {
[130] Fix | Delete
$split_url = explode( '/', $img_url );
[131] Fix | Delete
[132] Fix | Delete
if( ! isset( $size['mime-type'] ) || $size['mime-type'] !== 'image/gif' ) {
[133] Fix | Delete
$split_url[ count( $split_url ) - 1 ] = $size['file'];
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
return array(
[137] Fix | Delete
'url' => implode( '/', $split_url ),
[138] Fix | Delete
'width' => $width,
[139] Fix | Delete
'height' => $height,
[140] Fix | Delete
'attachment_id' => $attachment_id
[141] Fix | Delete
);
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
// Requested image size doesn't exists, so let's create one
[146] Fix | Delete
if ( true === $crop ) {
[147] Fix | Delete
add_filter( 'image_resize_dimensions', 'themify_img_resize_dimensions', 10, 5 );
[148] Fix | Delete
}
[149] Fix | Delete
// Patch meta because if we're here, there's a valid attachment ID for sure, but maybe the metadata is not ok.
[150] Fix | Delete
if ( empty( $meta ) ) {
[151] Fix | Delete
$meta['sizes'] = array( 'large' => array() );
[152] Fix | Delete
}
[153] Fix | Delete
// Generate image returning an array with image url, width and height. If image can't be generated, original url, width and height are used.
[154] Fix | Delete
$image = themify_make_image_size( $attachment_id, $width, $height, $meta, $img_url );
[155] Fix | Delete
[156] Fix | Delete
if ( true === $crop ) {
[157] Fix | Delete
remove_filter( 'image_resize_dimensions', 'themify_img_resize_dimensions', 10 );
[158] Fix | Delete
}
[159] Fix | Delete
$image['attachment_id'] = $attachment_id;
[160] Fix | Delete
return $image;
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
if ( ! function_exists( 'themify_make_image_size' ) ) {
[164] Fix | Delete
/**
[165] Fix | Delete
* Creates new image size.
[166] Fix | Delete
*
[167] Fix | Delete
* @uses get_attached_file()
[168] Fix | Delete
* @uses image_make_intermediate_size()
[169] Fix | Delete
* @uses wp_update_attachment_metadata()
[170] Fix | Delete
* @uses get_post_meta()
[171] Fix | Delete
* @uses update_post_meta()
[172] Fix | Delete
*
[173] Fix | Delete
* @param int $attachment_id
[174] Fix | Delete
* @param int $width
[175] Fix | Delete
* @param int $height
[176] Fix | Delete
* @param array $meta
[177] Fix | Delete
* @param string $img_url
[178] Fix | Delete
*
[179] Fix | Delete
* @return array
[180] Fix | Delete
*/
[181] Fix | Delete
function themify_make_image_size( $attachment_id, $width, $height, $meta, $img_url ):array {
[182] Fix | Delete
if($width!==0 || $height!==0){
[183] Fix | Delete
$upload_dir = themify_upload_dir();
[184] Fix | Delete
$attached_file=str_replace($upload_dir['baseurl'],$upload_dir['basedir'],$img_url);
[185] Fix | Delete
unset($upload_dir);
[186] Fix | Delete
if(!Themify_Filesystem::is_file ($attached_file)){
[187] Fix | Delete
$attached_file=get_attached_file( $attachment_id );
[188] Fix | Delete
}
[189] Fix | Delete
$source_size = apply_filters( 'themify_image_script_source_size', themify_get( 'setting-img_php_base_size', 'large', true ) );
[190] Fix | Delete
if ( $source_size !== 'full' && isset( $meta['sizes'][ $source_size ]['file'] ) ){
[191] Fix | Delete
$attached_file = str_replace( $meta['file'], trailingslashit( dirname( $meta['file'] ) ) . $meta['sizes'][ $source_size ]['file'], $attached_file );
[192] Fix | Delete
}
[193] Fix | Delete
unset($source_size);
[194] Fix | Delete
$resized = image_make_intermediate_size( $attached_file, $width, $height, true );
[195] Fix | Delete
if ( $resized && ! is_wp_error( $resized ) ) {
[196] Fix | Delete
// Save the new size in metadata
[197] Fix | Delete
$key = sprintf( 'resized-%dx%d', $width, $height );
[198] Fix | Delete
$meta['sizes'][$key] = $resized;
[199] Fix | Delete
$img_url = str_replace( basename( $img_url ), $resized['file'], $img_url );
[200] Fix | Delete
[201] Fix | Delete
wp_update_attachment_metadata( $attachment_id, $meta );
[202] Fix | Delete
// Save size in backup sizes, so it's deleted when the original attachment is deleted.
[203] Fix | Delete
$backup_sizes = get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true );
[204] Fix | Delete
if ( ! is_array( $backup_sizes ) ){
[205] Fix | Delete
$backup_sizes = array();
[206] Fix | Delete
}
[207] Fix | Delete
$backup_sizes[$key] = $resized;
[208] Fix | Delete
update_post_meta( $attachment_id, '_wp_attachment_backup_sizes', $backup_sizes );
[209] Fix | Delete
$img_url=esc_url($img_url);
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
// Return original image url, width and height.
[213] Fix | Delete
return array(
[214] Fix | Delete
'url' => $img_url,
[215] Fix | Delete
'width' => $width,
[216] Fix | Delete
'height' => $height
[217] Fix | Delete
);
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Disable the min commands to choose the minimum dimension, thus enabling image enlarging.
[225] Fix | Delete
*
[226] Fix | Delete
* @param $default
[227] Fix | Delete
* @param $orig_w
[228] Fix | Delete
* @param $orig_h
[229] Fix | Delete
* @param $dest_w
[230] Fix | Delete
* @param $dest_h
[231] Fix | Delete
* @return array
[232] Fix | Delete
*/
[233] Fix | Delete
function themify_img_resize_dimensions( $default, $orig_w, $orig_h, $dest_w, $dest_h ):array {
[234] Fix | Delete
// set portion of the original image that we can size to $dest_w x $dest_h
[235] Fix | Delete
$aspect_ratio = $orig_w / $orig_h;
[236] Fix | Delete
$new_w = $dest_w;
[237] Fix | Delete
$new_h = $dest_h;
[238] Fix | Delete
[239] Fix | Delete
if ( !$new_w ) {
[240] Fix | Delete
$new_w = (int)( $new_h * $aspect_ratio );
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( !$new_h ) {
[244] Fix | Delete
$new_h = (int)( $new_w / $aspect_ratio );
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
[248] Fix | Delete
[249] Fix | Delete
$crop_w = round( $new_w / $size_ratio );
[250] Fix | Delete
$crop_h = round( $new_h / $size_ratio );
[251] Fix | Delete
[252] Fix | Delete
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
[253] Fix | Delete
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
[254] Fix | Delete
[255] Fix | Delete
// the return array matches the parameters to imagecopyresampled()
[256] Fix | Delete
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
[257] Fix | Delete
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
if( ! function_exists( 'themify_get_attachment_id_from_url' ) ) :
[261] Fix | Delete
/**
[262] Fix | Delete
* Get attachment ID for image from its url.
[263] Fix | Delete
* @param deprecated $base_url
[264] Fix | Delete
*/
[265] Fix | Delete
function themify_get_attachment_id_from_url(string $url = '', $base_url = '' ):int {
[266] Fix | Delete
/* cache IDs, for when an image is displayed multiple times on the same page */
[267] Fix | Delete
static $cache = array();
[268] Fix | Delete
[269] Fix | Delete
// If this is the URL of an auto-generated thumbnail, get the URL of the original image
[270] Fix | Delete
$url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif|webp|bmp)$)/i', '', $url );
[271] Fix | Delete
if ( ! empty( $url ) ) {
[272] Fix | Delete
if ( ! isset( $cache[ $url ] ) ) {
[273] Fix | Delete
$cache[ $url ] = themify_get_attachment_id_cache( $url );
[274] Fix | Delete
}
[275] Fix | Delete
return $cache[ $url ];
[276] Fix | Delete
}
[277] Fix | Delete
return 0;
[278] Fix | Delete
}
[279] Fix | Delete
endif;
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Convert image URL to attachment ID, data is cached in a db for faster access
[283] Fix | Delete
*/
[284] Fix | Delete
function themify_get_attachment_id_cache(string $url ):int {
[285] Fix | Delete
$k=$url.'_id';
[286] Fix | Delete
$id = Themify_Storage::get($k);
[287] Fix | Delete
if ($id==='0' || ($id>0 && get_post_type($id)==='attachment') ) {
[288] Fix | Delete
return (int) $id;
[289] Fix | Delete
}
[290] Fix | Delete
$id = attachment_url_to_postid( $url );
[291] Fix | Delete
Themify_Storage::set($k,$id);
[292] Fix | Delete
return $id;
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Removes protocol and www from URL and returns it
[298] Fix | Delete
*
[299] Fix | Delete
* @return string
[300] Fix | Delete
*/
[301] Fix | Delete
function themify_remove_protocol_from_url( $url ) {//deprecated will be removed
[302] Fix | Delete
return preg_replace( '/https?:\/\/(www\.)?/', '', $url );
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
[306] Fix | Delete
function themify_create_webp(string $url):string{//@todo move to class
[307] Fix | Delete
[308] Fix | Delete
$res=$url;
[309] Fix | Delete
$info = pathinfo($res);
[310] Fix | Delete
if(!isset($info['extension'])){
[311] Fix | Delete
return $url;
[312] Fix | Delete
}
[313] Fix | Delete
$orig_ex = strtok($info['extension'],'?');
[314] Fix | Delete
if($orig_ex!=='png' && $orig_ex!=='jpg' && $orig_ex!=='jpeg' && $orig_ex!=='gif'){
[315] Fix | Delete
return $url;
[316] Fix | Delete
}
[317] Fix | Delete
static $available=null;
[318] Fix | Delete
if($available===NULL){
[319] Fix | Delete
$available=array();
[320] Fix | Delete
if(apply_filters('themify_disable_webp',false)===false){
[321] Fix | Delete
if(class_exists('Imagick',false)){
[322] Fix | Delete
$im = new Imagick();
[323] Fix | Delete
if (in_array('WEBP', $im->queryFormats('WEBP'),true) ) {
[324] Fix | Delete
$available['Imagick']=true;
[325] Fix | Delete
}
[326] Fix | Delete
$im->clear();
[327] Fix | Delete
$im=null;
[328] Fix | Delete
}
[329] Fix | Delete
if(!isset($available['Imagick']) &&function_exists('imagewebp') && (function_exists('imagecreatefromjpeg') || function_exists('imagecreatefrompng'))){
[330] Fix | Delete
$available['GD']=true;
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
}
[334] Fix | Delete
if(!empty($available)){
[335] Fix | Delete
$upload_dir= themify_upload_dir();
[336] Fix | Delete
$sameDomain=strpos($url,$upload_dir['baseurl'])!==false;
[337] Fix | Delete
if($sameDomain===false && strpos($url,'http')!==0){//relative to absolute
[338] Fix | Delete
$tmp_url = home_url($url);
[339] Fix | Delete
$sameDomain=strpos($tmp_url,$upload_dir['baseurl'])!==false;
[340] Fix | Delete
if($sameDomain===true){
[341] Fix | Delete
$res=$tmp_url;
[342] Fix | Delete
}
[343] Fix | Delete
}
[344] Fix | Delete
if(is_multisite()){
[345] Fix | Delete
if($sameDomain===false){
[346] Fix | Delete
if(is_subdomain_install()){
[347] Fix | Delete
$blog_name = explode('.',$_SERVER['SERVER_NAME']);
[348] Fix | Delete
$blog_name=$blog_name[0];
[349] Fix | Delete
if(strpos($url,$blog_name)===false){
[350] Fix | Delete
return $url;
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
else{
[354] Fix | Delete
if(!isset($_SERVER['SERVER_NAME']) || strpos($url,$_SERVER['SERVER_NAME'])===false){
[355] Fix | Delete
return $url;
[356] Fix | Delete
}
[357] Fix | Delete
static $site_url=null;
[358] Fix | Delete
if($site_url===null){
[359] Fix | Delete
$site_url = dirname(site_url());
[360] Fix | Delete
}
[361] Fix | Delete
if(strpos($url,$site_url)===false){
[362] Fix | Delete
return $url;
[363] Fix | Delete
}
[364] Fix | Delete
$blog_name =explode('/',trim(str_replace($site_url,'',$url),'/'));
[365] Fix | Delete
$blog_name=$blog_name[0];
[366] Fix | Delete
}
[367] Fix | Delete
static $sites=array();
[368] Fix | Delete
if(!isset($sites[$blog_name])){
[369] Fix | Delete
$blog = get_id_from_blogname($blog_name);
[370] Fix | Delete
if($blog===null){
[371] Fix | Delete
$sites[$blog_name]=false;
[372] Fix | Delete
return $url;
[373] Fix | Delete
}
[374] Fix | Delete
$currentBlog=pathinfo(get_site_url(),PATHINFO_FILENAME);
[375] Fix | Delete
switch_to_blog($blog );
[376] Fix | Delete
[377] Fix | Delete
$blog_upload_dir_info = wp_get_upload_dir();
[378] Fix | Delete
restore_current_blog();
[379] Fix | Delete
$sites[$blog_name] = array('basedir'=>$blog_upload_dir_info['basedir'],'baseurl'=>str_replace('/'.$currentBlog.'/','/'.$blog_name.'/',$blog_upload_dir_info['baseurl']));// bug in WP return the current blog name url,not switched
[380] Fix | Delete
}
[381] Fix | Delete
elseif($sites[$blog_name]===false){
[382] Fix | Delete
return $url;
[383] Fix | Delete
}
[384] Fix | Delete
$upload_dir=$sites[$blog_name];
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
elseif($sameDomain===false){
[388] Fix | Delete
return $url;
[389] Fix | Delete
}
[390] Fix | Delete
$res=str_replace($upload_dir['baseurl'],$upload_dir['basedir'],urldecode($res));
[391] Fix | Delete
if(strpos($res,'http')===0){
[392] Fix | Delete
return $url;
[393] Fix | Delete
}
[394] Fix | Delete
$resUrl=str_replace('.'.$orig_ex, '.webp', $res);
[395] Fix | Delete
if(is_file ($resUrl)){
[396] Fix | Delete
return str_replace($upload_dir['basedir'],$upload_dir['baseurl'],$resUrl);
[397] Fix | Delete
}
[398] Fix | Delete
if(!is_file ($res)){
[399] Fix | Delete
return $url;
[400] Fix | Delete
}
[401] Fix | Delete
$webp_quality = (int) themify_builder_get( 'setting-webp-quality', 'performance-webp_quality' );
[402] Fix | Delete
if ( empty( $webp_quality ) ) {
[403] Fix | Delete
$webp_quality = 5;
[404] Fix | Delete
}
[405] Fix | Delete
if(isset($available['Imagick'])){
[406] Fix | Delete
$im = new Imagick($res);
[407] Fix | Delete
$lowerExt=explode('/',$im->getImageMimeType());
[408] Fix | Delete
if(isset($lowerExt[1])){
[409] Fix | Delete
$lowerExt=str_replace('x-','',$lowerExt[1]);
[410] Fix | Delete
}else{
[411] Fix | Delete
$lowerExt=false;
[412] Fix | Delete
}
[413] Fix | Delete
if(($lowerExt!=='png' && $lowerExt!=='jpg' && $lowerExt!=='jpeg' && $lowerExt!=='gif') || $im->getImageWidth()>2560 || $im->getImageHeight()>2560){
[414] Fix | Delete
$im->clear();
[415] Fix | Delete
$im=null;
[416] Fix | Delete
return $url;
[417] Fix | Delete
}
[418] Fix | Delete
try {
[419] Fix | Delete
if($im->setImageFormat( 'webp' ) && $im->setOption( 'webp:method', $webp_quality ) && $im->setOption('webp:lossless','false') && $im->setOption('webp:low-memory', 'true') && $im->setOption('webp:use-sharp-yuv', 'true')) {
[420] Fix | Delete
[421] Fix | Delete
if (($lowerExt !== 'png' || ($im->setOption('webp:alpha-compression', 1) && $im->setOption('webp:alpha-quality', 85))) && $im->stripImage()) {
[422] Fix | Delete
[423] Fix | Delete
try {
[424] Fix | Delete
$webp = $lowerExt === 'gif' ? $im->writeImages($resUrl, true) : $im->writeImage($resUrl);
[425] Fix | Delete
}
[426] Fix | Delete
catch (Throwable $e ){
[427] Fix | Delete
$webp=false;
[428] Fix | Delete
}
[429] Fix | Delete
if(!$webp){
[430] Fix | Delete
if($lowerExt === 'gif') {
[431] Fix | Delete
try {
[432] Fix | Delete
$im->optimizeImageLayers();
[433] Fix | Delete
}
[434] Fix | Delete
catch (Throwable $e) {
[435] Fix | Delete
[436] Fix | Delete
}
[437] Fix | Delete
}
[438] Fix | Delete
$webp = file_put_contents($resUrl, ($lowerExt==='gif'?$im->getImagesBlob():$im->getImageBlob()));
[439] Fix | Delete
if ($webp) {
[440] Fix | Delete
$res = $resUrl;
[441] Fix | Delete
}else{
[442] Fix | Delete
Themify_Filesystem::delete($resUrl,'f');
[443] Fix | Delete
}
[444] Fix | Delete
}
[445] Fix | Delete
$im->clear();
[446] Fix | Delete
$im = null;
[447] Fix | Delete
}
[448] Fix | Delete
}
[449] Fix | Delete
}
[450] Fix | Delete
catch (Throwable $e ){
[451] Fix | Delete
$im->clear();
[452] Fix | Delete
$im=null;
[453] Fix | Delete
return $url;
[454] Fix | Delete
}
[455] Fix | Delete
}
[456] Fix | Delete
else{
[457] Fix | Delete
if(function_exists('exif_imagetype')){
[458] Fix | Delete
$size=image_type_to_mime_type(exif_imagetype($res));
[459] Fix | Delete
}
[460] Fix | Delete
elseif(function_exists('finfo_file')){
[461] Fix | Delete
$finfo = finfo_open(FILEINFO_MIME_TYPE);
[462] Fix | Delete
if($finfo!==false){
[463] Fix | Delete
$size=finfo_file($finfo, $res);
[464] Fix | Delete
finfo_close($finfo);
[465] Fix | Delete
}
[466] Fix | Delete
unset($finfo);
[467] Fix | Delete
}
[468] Fix | Delete
if(empty($size)){
[469] Fix | Delete
if(function_exists('mime_content_type')){
[470] Fix | Delete
$size = mime_content_type($res);
[471] Fix | Delete
}
[472] Fix | Delete
else{
[473] Fix | Delete
$size = getimagesize($res);
[474] Fix | Delete
if(!isset($size['mime']) || !isset($size[0]) || !isset($size[1]) || $size[0]>2560 || $size[1]>2560){
[475] Fix | Delete
return '';
[476] Fix | Delete
}
[477] Fix | Delete
$size=$size['mime'];
[478] Fix | Delete
}
[479] Fix | Delete
}
[480] Fix | Delete
if(empty($size)){
[481] Fix | Delete
return $url;
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
$size=explode('/',$size);
[485] Fix | Delete
if(!isset($size[1])){
[486] Fix | Delete
return $url;
[487] Fix | Delete
}
[488] Fix | Delete
$lowerExt=$size[1];
[489] Fix | Delete
unset($size);
[490] Fix | Delete
if($lowerExt!=='png' && $lowerExt!=='jpg' && $lowerExt!=='jpeg'){
[491] Fix | Delete
return $url;
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
switch($lowerExt){
[495] Fix | Delete
case 'jpeg':
[496] Fix | Delete
case 'jpg':
[497] Fix | Delete
if(!function_exists('imagecreatefromjpeg')){
[498] Fix | Delete
return $url;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function