Venom89 Posted October 7, 2009 Share Posted October 7, 2009 Hey everyone. Having a little bit of trouble with using the php image functions and using images I have retrieved from my images database. Basically I am pulling out an image from the database and trying to resize it to fit my needs. Here is the signature of my function: function getImage($image_src, $imageType, $newWidth, $newHeight) Where $image_src is the image data itself. My problem is that most of the image functions files (e.g. imagecreatefromjpeg) require a filename as a parameter, not the image data itself. Is there any way around this? /** @param $image_src The image data itself (pulled from blob in a database) @param $image_type The type of the image (e.g. jpeg) @param $newWidth The width we are aiming for @param $newHeight The height we are aiming for */ function getImage($image_src, $imageType, $newWidth, $newHeight) { // Get the original geometry and calculate scales list($width, $height) = getimagesize($img_src); // Won't work needs filename $xscale=$width/$newWidth; $yscale=$height/$newHeight; // Recalculate new size with default ratio if ($yscale>$xscale) { $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); if ($imageType == "image/jpeg") { $imageTmp = imagecreatefromjpeg ($image_src); } else //if image is png etc. { } imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } Link to comment https://forums.phpfreaks.com/topic/176771-image-functions-and-filenames/ Share on other sites More sharing options...
jon23d Posted October 7, 2009 Share Posted October 7, 2009 Yes, write your image data to a file: file_put_contents('a_filename_and_path', $image_data); Link to comment https://forums.phpfreaks.com/topic/176771-image-functions-and-filenames/#findComment-932172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.