我有一个系统,您可以从文件夹上传图像,压缩后它会自动显示在某个页面上。它适用于PNG,GIF和JPG,但我一直在尝试添加BMP支持,但它给了我错误。我找不到很多其他的BNP代码替代品,有什么建议吗?
这是重要部分的样子:
$dsg_allowed_extensions = array();
if ( ! isset($dsg_allow_gif) || $dsg_allow_gif == TRUE ) {
array_push($dsg_allowed_extensions, 'gif');
}
if ( ! isset($dsg_allow_bmp) || $dsg_allow_bmp == TRUE ) {
array_push($dsg_allowed_extensions, 'bmp');
}
if ( ! isset($dsg_allow_jpg) || $dsg_allow_jpg == TRUE ) {
array_push($dsg_allowed_extensions, 'jpg');
array_push($dsg_allowed_extensions, 'jpeg');
}
if ( ! isset($dsg_allow_png) || $dsg_allow_png == TRUE ) {
array_push($dsg_allowed_extensions, 'png');
}
function dsgLoadImage($image) {
switch ($image['type']) {
case IMAGETYPE_JPEG: return imagecreatefromjpeg( $image['fullpath'] );
case IMAGETYPE_GIF: return imagecreatefromgif( $image['fullpath'] );
case IMAGETYPE_BMP: return imagecreatefrombmp( $image['fullpath'] );
case IMAGETYPE_PNG: return imagecreatefrompng( $image['fullpath'] );
case IMAGETYPE_JPEG:
if (! @imagejpeg($new_image, $destination_path, $compression) ) {
throw new Exception ("Writing to file failed.");
}
break;
case IMAGETYPE_GIF:
if (! @imagegif($new_image, $destination_path) ) {
throw new Exception ("Writing to file failed.");
}
break;
case IMAGETYPE_PNG:
if (! @imagepng($new_image, $destination_path) ) {
throw new Exception ("Writing to file failed.");
}
break;
case IMAGETYPE_BMP:
if (! @imagebmp($new_image, $destination_path) ) {
throw new Exception ("Writing to file failed.");
答案 0 :(得分:0)
据我所知,PHP中不存在函数imagecreatefrombmp(),因为GD2库不支持BMP格式的文件。有一个imagecreatefromwbmp()(注意'w')适用于WBMP文件;不是你需要的。来自Bytes社区的人写了一个天真的替代缺失函数(并未涵盖所有情况)。请参阅his post。