: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$im = imagecreatefromjpeg($res);
if(!function_exists('imagecreatefrompng')){
if(function_exists('imagepalettetotruecolor')){
$im = imagecreatefrompng($res);
if($im!==false && (!imagepalettetotruecolor($im) || !imagealphablending($im, true) || !imagesavealpha($im, true))){
$pngimg = imagecreatefrompng($res);
if ($w !== false && $h !== false) {
$im = imagecreatetruecolor($w, $h);
if ($im !== false && imagealphablending($im, false) && imagesavealpha($im, true)) {
// By default, the canvas is black, so make it transparent
$trans = imagecolorallocatealpha($im, 0, 0, 0, 127);
if($trans===false || !imagefilledrectangle($im, 0, 0, $w - 1, $h - 1, $trans) || !imagecopy($im, $pngimg, 0, 0, 0, 0, $w, $h)) {
$quality = array( 0 => 40, 1 => 50, 2 => 60, 3 => 70, 4 => 80, 5 => 90, 6 => 100 );
$webp =imagewebp($im, $res, $quality[ $webp_quality ] );
Themify_Filesystem::delete($res,'f');
return !empty($webp)?str_replace($upload_dir['basedir'],$upload_dir['baseurl'],$res):$url;
function themify_get_video_size(string $url):?array{
$found=Themify_Storage::get($k);
$attachment_id=themify_get_attachment_id_from_url($url);
$meta=wp_get_attachment_metadata( $attachment_id );
require_once ABSPATH . 'wp-admin/includes/media.php';
$meta=wp_read_video_metadata(get_attached_file($attachment_id));
'w'=>isset($meta['width'])?$meta['width']:'',
'h'=>isset($meta['height'])?$meta['height']:'',
's'=>isset($meta['filesize'])?$meta['filesize']:'',
'f'=>isset($meta['fileformat'])?$meta['fileformat']:'',
'l'=>isset($meta['length_formatted'])?$meta['length_formatted']:'',
't'=>isset($meta['mime_type'])?$meta['mime_type']:''
Themify_Storage::set($k,$found,MONTH_IN_SECONDS*6);
$found=json_decode($found,true);
if($found===null && Themify_Storage::delete($k)!==false){
return themify_get_video_size($url);
function themify_get_image_size(?string $url,bool $isLocal=false,int $color=0){//@todo move to class
if(!isset($url[2]) || strtok(pathinfo($url,PATHINFO_EXTENSION),'?')==='svg'){
if(strpos($url,'x',3)!==false){
preg_match('/\-(\d+x\d+)\./i',$url,$m,0,3);
$size= array('w'=>$m[0],'h'=>$m[1]);
elseif(strpos($url,'gravatar.com')!==false){
$parts = parse_url($url,PHP_URL_QUERY);
parse_str($parts, $query_params);
if(!empty($query_params['s'])){
return array('w'=>$query_params['s'],'h'=>$query_params['s']);
if(!isset($size) || $color>0){
$found=Themify_Storage::get($k);
if(strpos($found,':')!==false){
$found=explode(':',$found)[1];
$found=explode('-',$found);
$size= array('w'=>$found[0],'h'=>$found[1]);
$size['c']=explode(',',$found[2]);
if(defined('THEME_URI') && strpos($url,THEME_URI)!==false){
$url=str_replace(THEME_URI,THEME_DIR,$url);
$upload_dir = themify_upload_dir();
if(strpos($url,$upload_dir['baseurl'])!==false){
$url=str_replace($upload_dir['baseurl'],$upload_dir['basedir'],$url);
if (class_exists('Themify_Get_Image_Size',false) || is_file( THEMIFY_DIR . '/class-themify-get-image-size.php' ) ) {
$is = apply_filters('tf_disable_remote_size', true);
require_once THEMIFY_DIR . '/class-themify-get-image-size.php';
$size=Themify_Get_Image_Size::getSize($url,$isLocal);
if($size===false && $isLocal===true && function_exists('getimagesize')){
$size=getimagesize($url);
$size=empty($size)?false:array('w'=>$size[0],'h'=>$size[1]);
$value=$size['w'].'-'.$size['h'];
if($color>0 && $isLocal===true ){
$colors=themify_get_image_color($url,$size['w'],$size['h'],$color);
$value.='-'.implode(',',$colors);
Themify_Storage::set($k,$value);
function themify_get_image_color(string $dir,int $w,int $h,int $rows=4):array{//@todo move to class
if($w<=2560 || $h<=2560){
if(class_exists('Imagick',false)){
$ext=strtok(pathinfo($dir,PATHINFO_EXTENSION),'?');
if(function_exists('imagecreatefrompng')){
$im = imagecreatefrompng($dir);
elseif($ext==='jpg' || $ext==='jpeg'){
if(function_exists('imagecreatefromjpeg')){
$im = imagecreatefromjpeg($dir);
if(function_exists('imagecreatefromgif')){
$im = imagecreatefromgif($dir);
if(function_exists('imagecreatefromwebp')){
$im = imagecreatefromwebp($dir);
elseif($ext==='bmp' && function_exists('imagecreatefrombmp')){
$im = imagecreatefrombmp($dir);
for($y=1;$y<=$rows;++$y){
$y_coord=$y*$box_h-$half_h;
for($x=1;$x<=$rows;++$x){
$x_coord=$x*$box_w-$half_w;
$tmp=$im->getImagePixelColor($x_coord,$y_coord)->getColor(0);
$color=array('red'=>$tmp['r'],'green'=>$tmp['g'],'blue'=>$tmp['b']);
$color=imagecolorsforindex($im, imagecolorat($im, $x_coord,$y_coord));
if ($color['green']>=256){
if ($color['blue']>=256){
$colors[]=substr('0'.dechex($color['red']),-2).substr('0'.dechex($color['green']),-2).substr('0'.dechex($color['blue']),-2);