不起作用?
$ image = imagecreatefrompng(" $ filename");
我的裁剪照片的PHP代码
$filename="yaaa.png";
$width: 10px;
$height: 10px;
$image = imagecreatefrompng("$filename");
$thumb_width = $width;
$thumb_height = $height;
$width = imagesx($image);
$height = imagesy($image);
$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;
if ( $original_aspect >= $thumb_aspect )
{
$new_height = $thumb_height;
$new_width = $width / ($height / $thumb_height);
}
else
{
$new_width = $thumb_width;
$new_height = $height / ($width / $thumb_width);
}
$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width) / 2,
0 - ($new_height - $thumb_height) / 2,
0, 0,
$new_width, $new_height,
$width, $height);
imagepng($thumb, $filename, 100);
imagedestroy($thumb);
我运行此代码但没有工作,我的图片是黑暗的,文字"图片无效"
为什么?
答案 0 :(得分:0)
$width
和$height
的定义无效。改变它:
$width = 10;
$height = 10;