illegaljose Posted July 13, 2009 Share Posted July 13, 2009 I am trying to use GD to take multiple jpeg's; resize, crop, and stamp them on a new 3000x2400px image. I have gathered the below scripts but I do not have enough php experience to put it all together. please advise! crop: // don't forget to include the photo class @include photo.php; // instantiate the photo class. Without a file upload, you pass // an array of info about the photo you're going to crop. Note that // because we're not cropping a file upload (though you could // certainly do that), the tmp_name and the name are the same. $photo = new Photo(array('name'=>'mydirectory/myfile','tmp_name=>'mydirectory/myfile')); // we pass the width and height we want to crop to to the doCenterCrop function $width = 190; $height = 131; $photo->doCenterCrop($width,$height); resize: <?php // The file $filename = 'test.jpg'; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width, $height) = getimagesize($filename); $new_width = $width $new_height = $height // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagejpeg($image_p, null, 100); ?> stamp: <?php // Load the stamp and the photo to apply the watermark to $stamp = imagecreatefrompng('stamp.png'); $im = imagecreatefromjpeg('photo.jpeg'); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // Copy the stamp image onto our photo using the margin offsets and the photo // width to calculate positioning of the stamp. imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp)); // Output and free memory header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?> Link to comment https://forums.phpfreaks.com/topic/165746-php-gd/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.