construcali Posted July 28, 2011 Share Posted July 28, 2011 I need to insert a picture data into a table's cell of type medium blob. I'm grabbing the picture from an input file FILE['foto'] and sending it to a function where it's resized, this function is getFoto. Here I use the file_get_contents function to grab the source of the image and then the imagecreateimagefromstring function to create the image, if the imagecreatefromstring function returns a valid data, I resize the picture and send it back to the script creating a buffer zone and then grabbing its content with a variable that is returned. This works just fine with any jpg or jpeg file, but with pictures of format png or bmp or gif, the data returned from the imagecreatefromstring function seems to not be valid and thus the image is not resized and I get the error image. Would anyone please shed some light as why is this happening. I've been toying around with the imagecreatefrompng and even just moving the file to a location on my server and freading but that doesn't seem to work either. Any help would be greatly appreciated. Thanks This is the function function getFoto($Original) { if (!$Original['name']) { //not a valid image, use standard $TempName = "images/noimage.jpg"; $TempFile = fopen($TempName, "r"); $thumbnail = fread($TempFile, fileSize($TempName)); }else { //Get picture $picture = file_get_contents($Original['tmp_name']); $SourceImage = imagecreatefromstring($picture); if (!$SourceImage) { //No a valid image $TempName = "images/noimage.jpg"; $TempFile = fopen($TempName, "r"); $thumbnail = fread($TempFile, filesize($TempName)); }else { //create the thumbnail $width = imagesx($SourceImage); $height = imagesy($SourceImage); $newThumb = imagecreatetruecolor(600,480); //resize the image to 600 x 480 $result = imagecopyresampled($newThumb, $SourceImage, 0, 0, 0, 0, 600, 480, $width, $height); //mover la imagen a la nueve variable ob_start(); imagejpeg($newThumb); $thumbnail = ob_get_contents(); ob_end_clean(); } } return $thumbnail; } Quote Link to comment https://forums.phpfreaks.com/topic/243038-the-function-imagecreatefrom-string-is-only-returning-valid-date-with-jpg-why/ Share on other sites More sharing options...
phpSensei Posted July 28, 2011 Share Posted July 28, 2011 Are you running this on a local server? Quote Link to comment https://forums.phpfreaks.com/topic/243038-the-function-imagecreatefrom-string-is-only-returning-valid-date-with-jpg-why/#findComment-1248374 Share on other sites More sharing options...
construcali Posted July 28, 2011 Author Share Posted July 28, 2011 No, this is running on a host server. Quote Link to comment https://forums.phpfreaks.com/topic/243038-the-function-imagecreatefrom-string-is-only-returning-valid-date-with-jpg-why/#findComment-1248726 Share on other sites More sharing options...
phpSensei Posted July 28, 2011 Share Posted July 28, 2011 No, this is running on a host server. imagecreatefromstring() returns an image identifier representing the image obtained from the given data. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2 From the manual, i dont know if that has something to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/243038-the-function-imagecreatefrom-string-is-only-returning-valid-date-with-jpg-why/#findComment-1248745 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.