生成缩略图代码会生成具有644权限的空白图像

时间:2017-07-08 09:23:05

标签: php wordpress woocommerce thumbnails file-permissions

我使用自定义缩略图代码生成woo商务产品的缩略图。几天前工作正常。但突然间,它停止了工作。最近,php版本更新到7.0.20。我认为这是一个问题,但还没有找到任何解决方案。

以下是我正在使用的缩略图代码:

 function image_product_resize_crop_white_bg ( $src, $w, $h, $dest = null, $override = false, $createNewIfExists = false ) {     
    $ext = array_pop ( explode ('.', $src) );       
    $filenameSrc = str_replace (".$ext", '', basename($src) );      
    $filename = "{$filenameSrc}-{$w}X{$h}";     
    $arrayUploadPath = wp_upload_dir();     
    $fileUploadSubDir = "/product/";        
    $fileUploadDir = $arrayUploadPath['basedir'] . "/product/";
    if(is_null($dest)) $dest = $fileUploadDir;              
    $i = null;      
    if( ! $override && $createNewIfExists ) {           
        $i = 0;         
        while ( file_exists("$dest$filename-$i.png") ) $i++;            
            $i = '-' . $i;      
    }               
    $fileFullPath = "$dest$filename$i.png";     
    $fileFullUrl = $arrayUploadPath['baseurl'] . $fileUploadSubDir . $filename.$i .'.png';
    if( ! $override && file_exists($fileFullPath) ) return $fileFullUrl;
    if( $override ) @unlink($fileFullPath);
    switch ($ext) {         
        case 'jpg':         
        case 'jpeg' : $image = imagecreatefromjpeg($src); break;            
        case 'gif' : $image = imagecreatefromgif($src); break;          
        case 'png' : $image = imagecreatefrompng($src); break;          
        case 'wbmp' :           
        case 'bmp': $image = imagecreatefromwbmp($src); break;          
        default: $image = imagecreatefromgd2($src);     
    }               
    $width = imagesx($image);       
    $height = imagesy($image);          
    $original_aspect = $width / $height;        
    $thumb_aspect = $w / $h;                
    if ( $original_aspect >= $thumb_aspect ) {          
        if( $width > $w ) {             
            $new_height = $h;               
            $new_width = $width / ($height / $h);           
        }else{              
            $new_height = $height;              
            $new_width = $width;            
        }                   
    } else {           
        if ( $width > $w ) {              
            $new_width = $w;               
            $new_height = $height / ($width / $w);         
        } else {              
            $new_width = $width;              
            $new_height = $height;         
        }       
    }
    $thumb = imagecreatetruecolor($w, $h);

    imagealphablending($thumb, false);
    imagesavealpha($thumb, true);

    $transparent = imagecolorallocate($thumb, 255, 255, 255);
    imagecolortransparent($thumb, $transparent);
    imagefilledrectangle($thumb, 0, 0, $w, $h, $transparent);



    imagecopyresampled($thumb,$image,0-($new_width - $w) / 2,0 - ($new_height - $h) / 2,0, 0,$new_width, $new_height,$width, $height);
    imagepng($thumb, $fileFullPath, 9);
    imagedestroy($image);
    return $fileFullUrl;
}

使用此代码,空白缩略图以644权限生成。早些时候,缩略图正在以755的许可生成。

但是,在wordpress管理面板的媒体上上传图像,正确生成图像。

任何人都可以帮我解决这个问题。我的网站是现场直播,而且不会产生任何网站。

0 个答案:

没有答案