Given n images of different height and width, but all of them are taller than 640px
Is there a way to first resize the images that are bigger than 640px to 640px while maintaining the aspect ratio
and then stitch all of those n images together in one long filmstrip of an image?
The new image obviously will be of height:640px but the total width will be the sum of the resized n images.
I want the user to upload n images and then have php create a really wide image of known height.
I'm looking at GD but I am open to other suggestions, this is my first venture into image manipulation in php.
if possible, i would also like to align them with a margin of x pixels, and make the margins black.
I guess one way would be to first resize, then estimate the total width, create a black canvas and paste them all onto the canvas.
But how?
Resizing and merging several images to one image
Moderator: General Moderators
Re: Resizing and merging several images to one image
I would go with GD, I use it for generating and resizing images all the time and I've never had any complaints about it.
Code: Select all
//fix the IE problems of not reloading the newest version of the image
header("Expires: Mon, 14 Jul 1789 12:30:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$base_image = 'myimage.png'; //the image you're trying to resize
$percent = 0.75; //percentage to scale the image up or down 1 = 100%, 0.5 = 50% smaller, etc
//Calculate new dimensions
list($width, $height) = getimagesize($base_image);
$new_width = $width * $percent;
$new_height = $height * $percent;
//get color scheme from image
$image_p = @imagecreatetruecolor($new_width, $new_height);
//get image data
$image = imagecreatefrompng($base_image);
//re-size the image (and you can also reposition it but this just has it starting to draw it at 0,0)
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//this will preserve alpha transparency
imagesavealpha($image_p, true);
//save the final image into a variable $destfile
imagepng($image_p, $destfile);
echo "<img src=\"$destfile?fool=" . md5(time()) . "\" />"; //this is so older versions of IE won't cache the image
?>
Re: Resizing and merging several images to one image
Thank you for a thorough answer. I will have a go at this later.Jade wrote:I would go with GD, I use it for generating and resizing images all the time and I've never had any complaints about it.
-s