我正在维护一个旧网站。现在我的客户想要添加 6000 多种产品。产品图片有不同的尺寸。我必须申请批处理。我必须将它们全部调整为 230x230 的拇指大小。如果来自 PHP,有什么办法吗?如果是怎么办?
我必须从主图像文件夹中的不同文件夹中读取所有内容。此图像文件夹有 40 个子文件夹。每个文件夹名称是类别名称,里面的图像是产品(图像)。
if(imagecopyresampled($NewCanves, $NewImage,0, 0, 0, 0, $NewWidth, $NewHeight, $iWidth, $iHeight))
{
// copy file
if(imagejpeg($NewCanves,$DestImage,$Quality))
{
imagedestroy($NewCanves);
return true;
}
}
最佳答案
使用 php,您可以使用以下命令读取文件夹中的文件
$images= glob("*"); // * will address all files
// or
$images= glob("*.jpg"); // this will address only jpg images
然后遍历 $images
foreach ($images as $filename) {
//resize the image
if(resizeImage($imagePath,$destPath,$NewImageWidth,$NewImageHeight,$Quality)){
echo $filename.' resize Success!<br />';
}
}
function resizeImage($SrcImage,$DestImage, $MaxWidth,$MaxHeight,$Quality)
{
list($iWidth,$iHeight,$type) = getimagesize($SrcImage);
//if you dont want to rescale image
$NewWidth=$MaxWidth;
$NewHeight=$MaxHeight;
$NewCanves = imagecreatetruecolor($NewWidth, $NewHeight);
// Resize Image
if(imagecopyresampled($NewCanves, $NewImage,0, 0, 0, 0, $NewWidth, $NewHeight, $iWidth, $iHeight))
{
// copy file
if(imagejpeg($NewCanves,$DestImage,$Quality))
{
imagedestroy($NewCanves);
return true;
}
}
}
关于php - 如何使用 PHP 批量调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22402999/