ghostrider.k9 Posted July 2, 2008 Share Posted July 2, 2008 Hi Ppl really need your help cos i am stuck here. I need to resize and image and merge it with another image in my folder. i need your help.. <?php //Function for unidentified extensions of images function open_image ($file) { $extension = strrchr($file, '.'); $extension = strtolower($extension); switch($extension) { case '.jpg': case '.jpeg': $im = @imagecreatefromjpeg($file); break; case '.gif': $im = @imagecreatefromgif($file); break; default: $im = false; break; } return $im; } // Load image $image = open_image('test.jpg'); if ($image === false) { die ('Unable to open image'); } // Get original width and height $width = imagesx($image); $height = imagesy($image); $aspect_ratio=round($height/$width,2); header('Content-type: image/jpeg'); //Width is fixed for images where width is more than height $new_width = 300; //New Height $new_height = round((300/$width)*$height,0); //shrink the image with the new Height $image_resized = imagecreatetruecolor($new_width, $new_height); //Create the White Border $horz = imagecreatefromjpeg("images/whiteborder.jpg"); //Create the Second Image $vert = imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); //Get the height of the resized Image $height_resized = imagesy($vert); //Merge the Pixels imagecopymerge($horz, $vert, 1, 113-($height_resized/2), 0, 0, 298, $height_resized, 100); //Create the Converted Image imagejpeg($horz); //Destroy The Images imagedestroy($horz); imagedestroy($vert); ?> thanks.. Quote Link to comment Share on other sites More sharing options...
ghostrider.k9 Posted July 2, 2008 Author Share Posted July 2, 2008 I got the solution but i need to save the result image into my folder How to?? <?php header("Content-type: image/jpeg"); function resizeimg($image) { $x = @getimagesize($image); $width = $x[0]; $height = $x[1]; $new_width = round((225/$height)*$width,0); $new_height = round((300/$width)*$height,0); $new = @ImageCreateFromJPEG($image) or $new = @ImageCreateFromPNG($image) or $new = @ImageCreateFromGIF($image) or $new = false; if(!$new) { readfile($new); } else { $thumb = @ImageCreateTrueColor($new_width, $new_height); @ImageCopyResampled($thumb, $new, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $thumb; } return false; } $image = resizeimg('test4.jpg'); $horz = imagecreatefromjpeg("images/whiteborder.jpg"); $height_resized = imagesy($image); $width_resized = imagesx($image); imagecopymerge($horz, $image, 150-($width_resized/2), 113-($height_resized/2), 0, 0, $width_resized, $height_resized, 100); imagejpeg($horz); imagedestroy($horz); imagedestroy($vert); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 Add the path that you'd like to save it to as the second parameter to the imagejpeg call. Quote Link to comment Share on other sites More sharing options...
severndigital Posted July 2, 2008 Share Posted July 2, 2008 correct you last imagejpeg($horz); should look like this. imagejpeg($horz,'locationto/file.jpg'); make sure folder is chmod 777 .. i've have permission problems in the past doing this. Quote Link to comment Share on other sites More sharing options...
ghostrider.k9 Posted July 3, 2008 Author Share Posted July 3, 2008 thanks alot bros... Quote Link to comment 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.