Jassim Posted July 29, 2021 Share Posted July 29, 2021 (edited) Hi, I am trying to create a mobile version of my already uploaded file using below code but getting this error imagecreatefrompng(): is not a valid PNG file Here is the code: if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploadedFile)) { $resource = imagecreatefrompng($uploadedFile); $small_file = imagescale($resource , 500, 400); $small_file = imagepng($small_file); $newSmallFile = "mobile-" . $gallery_uuid . '.png'; $uploadedSmallFile = $uploaddir . $newSmallFile; echo $uploadedSmallFile; if (move_uploaded_file($small_file, $uploadedSmallFile)) { } else { echo json_encode("error"); } } else { echo json_encode("error"); } Kindly help.. Thanks, Jassim Edited July 29, 2021 by requinix removing link Quote Link to comment https://forums.phpfreaks.com/topic/313453-imagecreatefrompng-is-not-a-valid-png-file/ Share on other sites More sharing options...
requinix Posted July 29, 2021 Share Posted July 29, 2021 Trying to imagecreatefrompng() with an uploaded file will only work if the uploaded file was a PNG image. Use getimagesize() to detect whether the file is an image and, if so, what type it is. Quote Link to comment https://forums.phpfreaks.com/topic/313453-imagecreatefrompng-is-not-a-valid-png-file/#findComment-1588708 Share on other sites More sharing options...
Jassim Posted July 30, 2021 Author Share Posted July 30, 2021 I am getting the following: IMAGE INTO START HERE ///// Array ( [ 0 ] => 1600 [ 1 ] => 900 [ 2 ] => 2 [ 3 ] => width="1600" height="900" [bits ] => 8 [channels ] => 3 [mime ] => image/jpeg ) ///// IMAGE INTO END HERE<br /> the original file is a JPG but I copying it as PNG to standarize it so the file on my FTP after moving is a PNG Quote Link to comment https://forums.phpfreaks.com/topic/313453-imagecreatefrompng-is-not-a-valid-png-file/#findComment-1588718 Share on other sites More sharing options...
Barand Posted July 30, 2021 Share Posted July 30, 2021 The clue is in the function name. imagecreatefrompng() is for creating GD images from a PNG file. Check the manual and see if can find a similar function that might be suitable for reading a jpg file. Once you have created the image, you can then output it as a png file. Quote Link to comment https://forums.phpfreaks.com/topic/313453-imagecreatefrompng-is-not-a-valid-png-file/#findComment-1588720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.