Jump to content

The function imagecreatefrom string is only returning valid date with jpg? why?


Recommended Posts

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;

}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.