【发布时间】:2014-07-28 08:11:06
【问题描述】:
我正在制作缩略图,出于某种原因,我的输出尺寸正确,但始终是黑色的。我看到另一个关于类似主题的 Stack Overflow 帖子,但在他的案例中,他错误地传递了参数。
我正在从摄像机捕获图像,然后使用此代码:
$data = base64_decode($data); // the data will be saved to the db
$image = imagecreatefromstring($data); // need to create an image to grab the width and height
$img_width = imagesx($image);
$img_height = imagesy($image);
// calculate thumbnail size
$new_height = 100;
$new_width = floor( $img_width * ( 100 / $img_height ) );
// create a new temporary image
$new_image = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
$url = IMGDIR.$imgname;
$thumburl = IMGDIR."thumb/".$imgname;
// save image and thumb to disk
imagepng($image,$url);
imagepng($new_image,$thumburl);
我得到的结果是两个文件都保存到了正确的目录中,大小都正确,但缩略图全是黑色的。我一定缺少一些简单的东西。有什么想法吗?
【问题讨论】:
标签: php image-scaling