你现在的位置:首页 > PHP网站建设知识库 > PrestaShop > 正文

PrestaShop批量重新生成图片的代码

有时,我们会遇到之前上传的网站图片自动生成的缩略图不满意,需要重新生成图片。以下是prestashop批量重新生成图片的代码,如下:

define(‘_PS_ADMIN_DIR_’, getcwd());


define(‘PS_ADMIN_DIR’, _PS_ADMIN_DIR_); // Retro-compatibility

include(PS_ADMIN_DIR.’/../config/config.inc.php’);
include(PS_ADMIN_DIR.’/functions.php’);
@include(PS_ADMIN_DIR.’/toolbar.php’);
include(PS_ADMIN_DIR.’/header.inc.php’);

ob_implicit_flush(true);
@ini_set(‘display_errors’, ‘off’);
@set_time_limit(0);
@ini_set(‘max_execution_time’, 0);
@ini_set(‘memory_limit’, ’8000M’);

$images = Image::getAllImages();
$type = ImageType::getImagesTypes(‘products’);

echo ‘

Step 1 OK~

’;
ob_flush();

 

foreach ($images as $image){
$existing_img = ‘../img/p/’.chunk_split($image['id_image'], 1, ‘/’).$image['id_image'].’.jpg’;
if (file_exists($existing_img) && filesize($existing_img)){
foreach ($type as $imageType){
$newImg = str_replace(‘.jpg’, ‘-’.$imageType['name'].’.jpg’, $existing_img);
if(!file_exists($newImg)){
if (!imageResize($existing_img, $newImg, $imageType['width'], $imageType['height']))
{
file_put_contents(‘original_image_fail.log’, $existing_img.”\r\n”, FILE_APPEND);
}
}
}
}else{
file_put_contents(‘original_image_missing.log’, $existing_img.”\r\n”, FILE_APPEND);
}
}

echo ‘

End! Total:’.count($images).’ OK~

’;

 

include(PS_ADMIN_DIR.’/footer.inc.php’);
?>