无法使用php制作上传图像的缩略图

时间:2012-03-28 20:21:17

标签: php image

成功上传图像文件后,我需要制作图像缩略图。我写了这个函数,但它似乎不起作用。希望有人能提供帮助。感谢

function make_thumb( $src, $thumbDest, $thumbWidth ){
    $sourceImage  = imagecreatefromjpeg( $src );
    $theWidth     = imagesx( $sourceImage );
    $theHeight    = imagesy( $sourceImage );

    $thumbHeight = floor( $theHeight * ( $thumbWidth / $theWidth ) );
    $tempImage   = imagecreatetruecolor( $thumbWidth, $thumbHeight );
    imagecopyresized( $tempImage, $sourceImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $theWidth, $theHeight );

    imagejpeg( $tempImage, $thumbDest );
    imagedestroy( $tempImage );
    imagedestroy( $sourceImage );
}

1 个答案:

答案 0 :(得分:1)

如果您使用的是Linux,请检查/ var / log / httpd / error_log或/ var / log / apache2 / error_log以查看失败的原因(如果您关闭了错误报告。)

此外,它可能是由于文件权限问题。确保运行Apache或Web服务器的用户可以写入$ thumbDest目标文件夹/目录。