PHP convert none png image to png format using GD

Based on what kind of image it is you could select the correct function to open the file. Then, you just need imagepng() to convert.
Example:

$ori_ext = strtolower("Your upload file extension");
if( $ori_ext != 'png' )
{
    switch( $ori_ext )
    {
	    case 'jpg':
	    case 'jpeg':
	       $new_img = imagecreatefromjpeg("Your image file path");
	    break;
	    case 'gif':
	       $new_img = imagecreatefromgif("Your image file path");
	       break;
	 }
	
	//set the new file name and path
 	$final_file = $new_path . "/new_file.png";
 	imagepng($new_img, $final_file);
}

By Keenlio, September 25, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


eight + 2 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>