PrestaShop批量重新生成图片,使用以下代码:
<?php
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 ‘<pre>Step 1 OK~</pre>’;
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 ‘<h1>End! Total:’.count($images).’ OK~</h1>’;
include(PS_ADMIN_DIR.’/footer.inc.php’);
?>
(责任编辑:好模板) |