Convert .BMP to .PNG with PHP

可紊 提交于 2020-01-05 14:14:10

问题


I needed to be able to convert different image formats to the .PNG format. With the help of some others, I was able to make that happen. The only issue is, I also need to be able to convert .BMP files to .PNG without the use of ImageMagick.

Here is the code I used for the conversion of other files:

<?php
 $filename = "myfolder/test.jpg";
 $jpg = @imagecreatefromjpeg($filename);
 if ($jpg)
 {
   header("Content-type: image/png");
   imagepng($jpg);
   imagedestroy($jpg);
   exit;
 }
?>

If anyone knows how I would go about converting this, please let me know. All help is welcome and appreciated.


回答1:


There is a new opensource project on Github that allows reading and saving of BMP files (and other file formats) in PHP.

The project is called PHP Image Magician.




回答2:


There is not built in functionlaity for standard BMP's in GD. However, if you look at the documentation page for imagecreatefromwbmp there are some solutions posted by others you can try. The deal with reading the image data manually and constructing a GD image resource from it which could then be saved as whatever format.



来源:https://stackoverflow.com/questions/3955823/convert-bmp-to-png-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!