Harley1979 Posted August 31, 2008 Share Posted August 31, 2008 Hi, Got this script below that resizes my images proportionately. For those images that are displayed portrait though I want to make them fit into a second image which is basically just a background pattern. How can I merge the two images? Thanks <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $caption = trim($_REQUEST['caption']); if(empty($caption)){ $err = true; $titleErrMsg = "You must give a title"; } $title = $title.".jpg"; $section = $_REQUEST['section']; $grayscale = $_REQUEST['grayscale']; if($section == 0){ $err = true; $sectionErrMsg = "You must choose a section to upload to"; } $max_size = 8388608; $size = $_FILES['imagefile']['size']; $type = $_FILES['imagefile']['type']; $imageFile = $_FILES['imagefile']['tmp_name']; $src = imagecreatefromjpeg($imageFile); list($origWidth, $origHeight) = getimagesize($imageFile); if($type == "image/jpeg" || $type == "image/gif"){ ///////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// resize original image //////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////// $result1 = mysql_query("SELECT photo FROM gallery ORDER BY id desc LIMIT 1"); $row = mysql_fetch_row($result1); // modify file name if(empty($row[0])){$galleryName = 0;} $galleryName = $row[0] + 1; $galleryName = $galleryName.".jpg"; $result2 = mysql_query("SELECT photo FROM sitephotos ORDER BY id desc LIMIT 1"); $row = mysql_fetch_row($result2); // modify file name if(empty($row[0])){$sitePhotoName = 0;} $sitePhotoName = $row[0] + 1; $sitePhotoName = $sitePhotoName.".jpg"; $result3 = mysql_query("SELECT name FROM flyers ORDER BY id desc LIMIT 1"); $row = mysql_fetch_row($result3); // modify file name if(empty($row[0])){$flyerName = 0;} $flyerName = $row[0] + 1; $flyerName = $flyerName.".jpg"; // if our image is not the desired dimension, resample to default dimensions // define desireable dimensions switch ($section){ case 1: $heightDetermine = 352; $widthDetermine = 514; $savepath = '../gallery/'; $title = $galleryName; break; case 2: $heightDetermine = 137; $widthDetermine = 200; $savepath = '../sitephotos/'; $title = $sitePhotoName; break; case 3: $heightDetermine = 298; $widthDetermine = 210; $savepath = '../flyers/'; $title = $flyerName; } if($origWidth <= $origHeight && $origWidth >= $widthDetermine){ $newHeight = $heightDetermine; $newWidth = $origWidth * ($newHeight/$origWidth); } elseif($origWidth >= $origHeight && $origHeight >= $heightDetermine){ $newWidth = $widthDetermine; $newHeight = $origHeight * ($newWidth/$origWidth); } else { $newWidth = $origWidth; $newHeight = $origHeight; } $mainImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($mainImage, $src, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); if($grayscale == 'on'){ imagefilter($mainImage, IMG_FILTER_GRAYSCALE);} imagejpeg($mainImage, $savepath.$title, 100); imagedestroy($mainImage); imagedestroy($src); if(!isset($err)){ switch ($section){ case 1: $result1 = mysql_query("INSERT INTO gallery (photo, caption) VALUES ('$galleryName', '$caption')"); break; case 2: $result2 = mysql_query("INSERT INTO sitephotos (photo, caption) VALUES ('$sitePhotoName', '$caption')"); case 3: $result3 = mysql_query("INSERT INTO flyers (name, altText) VALUES ('$flyerName', '$caption')"); } } else { $imageErrMsg = "Incorrect file type";} } } error_reporting(E_ALL); ?> Quote Link to comment Share on other sites More sharing options...
phpknight Posted August 31, 2008 Share Posted August 31, 2008 Make a canvas just as big as the two images, and then place them side by side. If you have not already, it might help to just run it through in Photoshop to make sure you are thinking correctly about it. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 31, 2008 Share Posted August 31, 2008 The required function is imagecopymerge() Quote Link to comment Share on other sites More sharing options...
Harley1979 Posted August 31, 2008 Author Share Posted August 31, 2008 Thanks guys, But how do I place them side by side exactly? 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.