I need to convert a .JPG, .JPEG, .JPE, .GIF, etc to a .PNG from my PHP webpage without using ImageMagick. An开发者_运维百科y ideas?
Here is the code I found and am trying to work with:
<?php
header("content-type: image/png");
$original_filename = $_HTTP_POST_FILES['uploaded_file']; 
imagepng($original_filename,'border/testconvert.png',9);
?>
Who needs ImageMagick? Take a look at the built-in image functions using gd.
EDIT Basic example:
<?php
 $filename = "myfolder/test.jpg";
 $jpg = @imagecreatefromjpeg($filename);
 if ($jpg)
 {
   header("Content-type: image/png");
   imagepng($jpg);
   imagedestroy($jpg);
   exit;
 }
 // JPEG couldn't be loaded, maybe show a default image
?>
You can do more with this such as change compression and quality values etc, save the output to a file instead of outputting to the browser and so on - check the docs for further info :-)
Note that the image functions issue warnings/notices etc if there are problems loading an image, hence the use of the @ symbol to suppress, otherwise you'll get spurious output instead of just the image data.
function jpg2png($originalFile, $outputFile, $quality) {
    $image = imagecreatefromjpeg($originalFile);
    imagepng($image, $outputFile, $quality);
    imagedestroy($image);
}
Try something like this.
Tell me if if works!!
Good luck
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论