在过去几个小时里,我一直在尝试使用php裁剪文件夹中的所有图像,但经过一系列试验和失败后,我仍然无法成功运行代码;因此,我呼吁你的帮助PHP大师。谢谢
<?PHP
require ('plugin15.php');
$Dir = "/Users/Anay/Desktop/images2";
$DirEntries = scandir($Dir, 1);
foreach ($DirEntries as $Entry) {
echo $Entry;
}
$image = imagecreatefrompng("$Entry");
$copy = PIPHP_ImageCrop($image, 0, 0, 656, 1240);
if (!$copy) echo "Crop failed: Argument(s) out of bounds";
else imagepng($copy, "photo1.png");
?>
<?php
function PIPHP_ImageCrop($image, $x, $y, $w, $h)
{
$tw = imagesx($image);
$th = imagesy($image);
if ($x > $tw || $y > $th || $w > $tw || $h > $th)
return FALSE;
$temp = imagecreatetruecolor($w, $h);
imagecopyresampled($temp, $image, 0, 0, $x, $y,
$w, $h, $w, $h);
return $temp;
}
?>
编辑:收到错误
无法打开流:在...中拒绝权限
imagesx()期望参数1是资源,在...中给出布尔值
裁剪失败:超出范围的参数
答案 0 :(得分:0)
问题是您将$ Entry变量错误地传递给您的函数。删除$ Entry周围的""
,如下所示:
$image = imagecreatefrompng($Entry);