PHP - Resize The Thumbnail Pic
I want to resize both width and height of the thumb pic
this is the php code <?php $id_member=$_SESSION['rid']; if(!empty($foto1_name)) { $nama_file=$foto1_name; $anton->sekur_upload($nama_file); if($valid) { $abpath = "conf/i/"; @copy($foto1, $abpath."/".$foto1_name); $abang_dom=$abpath."/".$foto1_name; list($width, $height) = getimagesize($abang_dom); if($width>200) { make_thumb("$abpath/$foto1_name","conf/i/thumb/$foto1_name",200); } else { $tujuan="conf/i/thumb/".$foto1_name; rename($abang_dom, $tujuan); } } $foto_old_name=$foto1_name; $foto1_name=$id_member."_".$foto1_name; $foto1_name=strtolower($foto1_name); $foto1_name=str_replace(' ', '', $foto1_name); $asal1="conf/i/".$foto_old_name; $asal2="conf/i/thumb/".$foto_old_name; $tujuan1="conf/i/".$foto1_name; $tujuan2="conf/i/thumb/".$foto1_name; rename($asal1, $tujuan1); rename($asal2, $tujuan2); } I want to set the size to 100 x 100, which part of the code that I need to edit? Similar TutorialsHi! I'm looking for a script that can do the following: upload one or preferably fx. five image files(jpg) resizes them to a specific size if they exceeds that size. create a thumbnail No files above 100kb can be uploaded. uploaded and/or processed files must be renamed with a unique file name. Work with php5 I have searched the internet for a script like that, but I can't find one that matches my needs. Also, the code must include good comments and nott be to hard to understand. So as basic code as possible. I am working on an uploader and slowly getting it working, I am uploading 3 images at once, and setting arrays for each one as keys, with an increment of ++1. I am wanting to resize the image before it gets copied to the thumbnail folder. I have this code.
Everything works with it. As you see, I started on getting the file info, but after that I am totally stuck on what to do after to resize the image proportionally with a maximum width of xPX and height to match it without looking distorted. Any help would be really appreciated. Thank You. Any one know a tutorial for an easy to use thumbnail script which I can use with pictures stored in mysql database. hi guys, im trying to resize and save a thumbnail version of images uploaded to my site in a sub folder (thumbs). I've currently got: $image=imagecreatefromjpeg($filepath); list($width, $height) = getimagesize($filepath); $new_width = 200; $new_height= 150; $image_p=imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Save the image imagejpeg($image_p, '/thumbs'.$filepath); // Free up memory imagedestroy($image_p); but it appears to do nothing, but it also doesn't return any errors? could someone help me out please? thanks! Is there any way to generate a small image of the 1st page of a pdf document without using a 3rd party like imagemagic. The site is hosted a register.com so I am thinking I am going to be limited to the basic php functions. Hi, I have this image gallery slideshow, below the image, it's the thumbnail pics. but the size of the thumbnail pics is random...I want to set the size to be the same for all thumbnail pics, since I'm not the one wrote the code so I'm just guessing that this is the php code for the gallery: Code: [Select] <?php for($i=1;$i<10;$i++) { if(!empty($foto[$i])) { if($i==1) { $foto_first=$foto[$i]; } echo "<img border=0 width=0px height=2px src='conf/i/".$foto[$i]."'>"; $dataku.="'".$foto[$i]."': { thumbnail: 'thumb/".$foto[$i]."'},"; } else { $i--; break; } } $dataku=substr($dataku,0,-1); ?> <link rel="stylesheet" href="css/slideshow.css"> <script src="js/mootools-1.3.1-core.js"></script> <script src="js/mootools-1.3.1.1-more.js"></script> <script src="js/slideshow.js"></script> <script src="js/slideshow.flash.js"></script> <script> window.addEvent('domready', function(){ var data = { <?php echo $dataku;?>}; new Slideshow.Flash('flash', data, { color: ['tomato'],duration: 1500, delay: 10000, height: 400, hu: 'conf/i/', width: 500}); }); </script> <div style="padding-bottom:350px;padding-right:100px"> <div id="flash" class="slideshow"> <img src="conf/i/<?php echo $foto_first; ?>" alt="1" height=100px><br> </div> </div> is this the part that I need to add "size" to it? $dataku.="'".$foto[$i]."': { thumbnail: 'thumb/".$foto[$i]."'},"; I'm totally newb at php, so I have no clue at all Hi all, completely new at this and have got myself stuck! I am trying to display a thumbnail image by connecting to my database and retrieving the URL that points to the image. I know that the connection is working but I can't seem to get it to point to the image. Probably something really simple. Here's my code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Image Swap Using CSS</title> <style type="text/css"> body { margin: 0; padding: 0; background-color:#000000; } img { margin: 0; padding: 0; border: none; } .test { margin: 0; padding: 0; width: 99px; height: 130px; } .test a:hover img { visibility:hidden; } </style> </head> <body> <?php // connect to the database mysql_connect("********", "****") or die(mysql_error()); mysql_select_db("eliteescorting") or die(mysql_error()); $start=0; // expand on the searches $data=mysql_query("SELECT * FROM escorts WHERE base = 'manchester' ORDER BY RAND()"); $num_results=@mysql_num_rows($data); for($ii = $start;$ii < $num_results; $ii++){ ?> <div class="test"><a href="#"><img src="<?php echo $data[$ii]['thumb'];?>" /></a></div> <?php } ?> </body> </html> In my mySQL field 'thumb' contains the full URL of the image ie http://www............ This is just for testing, I'll get round to sorting out security issues later. Your help will be greatly appreciated! Regards, Nortski. I have a quick question about a script I wrote that searches all .jpg images in a directory (and it's sub-directories) and makes thumbnails of them. The problem I am having is that I am getting an internal server error after about 15 seconds. I have included my script, the class it requires, and my php.ini file that resides in the root of my site. I have searched for a couple of hours online and haven't been able to come up with an answer as to why I am getting that error. The thumbnail file... Code: [Select] <?php set_time_limit(0); require_once('classes/Create_Thumbnail.php'); $filter = '.jpg'; $directory = 'media'; // Do not include a trailing slash $it = new RecursiveDirectoryIterator("$directory"); foreach(new RecursiveIteratorIterator($it) as $file) { if (!((strpos(strtolower($file), $filter)) === false) || empty($filter)) { $items[] = preg_replace("#\\\#", "/", $file); } } foreach ($items as $item) { $photo = new Create_Thumbnail($item); $photo->createThumbnail(); } ?> The Create_Thumbnail class... Code: [Select] <?php class Create_Thumbnail { private $_photo; private $_photoBasename; private $_photoWidth; private $_photoHeight; private $_photoType; private $_resizedPhoto; private $_thumbFolder; private $_thumbWidth = 125; private $_thumbHeight = 125; private $_thumbSuffix = '_thumb'; private $_thumbnail; /** * Constructor retrieves photo's basename, extension, width, and height. */ public function __construct($photo) { $this->_photo = $photo; $this->_photoBasename = pathinfo($this->_photo, PATHINFO_FILENAME); $this->_extension = pathinfo($this->_photo, PATHINFO_EXTENSION); $this->_thumbFolder = dirname($photo) . '/'; list($this->_photoWidth, $this->_photoHeight, $this->_photoType) = getimagesize($this->_photo); } /** * Method to resize the original image to a size that is much closer to the desired thumbnail size. */ public function resize() { $photoRatio = $this->calculatePhotoRatio(); if ($photoRatio != 1) { $this->_resizedWidth = round($this->_photoWidth * $photoRatio); $this->_resizedHeight = round($this->_photoHeight * $photoRatio); } else { $this->_resizedWidth = $this->_thumbWidth; $this->_resizedHeight = $this->_thumbHeight; } $resource = $this->createResource($this->_photoType, $this->_photo); $resized = imagecreatetruecolor($this->_resizedWidth, $this->_resizedHeight); imagecopyresampled($resized, $resource, 0, 0, 0, 0, $this->_resizedWidth, $this->_resizedHeight, $this->_photoWidth, $this->_photoHeight); $this->_resizedPhoto = $this->_thumbFolder . $this->_photoBasename . '_resized.' . $this->_extension; $this->createNewImage($this->_photoType, $resized, $this->_resizedPhoto); imagedestroy($resource); imagedestroy($resized); return $this->_resizedPhoto; } /** * Method to create the thumbnail. */ public function createThumbnail() { $source = $this->resize(); list($width_original, $height_original, $type) = getimagesize($source); $base_name = pathinfo($source, PATHINFO_FILENAME); $base_name = str_replace('_resized', '', $base_name); $extension = pathinfo($source, PATHINFO_EXTENSION); $source_x = ($width_original / 2) - ($this->_thumbWidth / 2); $source_y = ($height_original / 2) - ($this->_thumbHeight / 2); $resource = $this->createResource($type, $source); $thumb = imagecreatetruecolor($this->_thumbWidth, $this->_thumbHeight); imagecopyresampled($thumb, $resource, 0, 0, $source_x, $source_y, $this->_thumbWidth, $this->_thumbHeight, $this->_thumbWidth, $this->_thumbHeight); $this->_thumbnail = $this->_thumbFolder . $base_name . $this->_thumbSuffix . '.' . $extension; $this->createNewImage($type, $thumb, $this->_thumbnail); unlink($source); return $this->_thumbnail; } /** * Method to create an image resource. */ public function createResource($type, $source) { switch ($type) { case 1: $resource = imagecreatefromgif($source); break; case 2: $resource = imagecreatefromjpeg($source); break; case 3: $resource = imagecreatefrompng($source); break; } return $resource; } /** * Method to calculate the photo ratio. */ public function calculatePhotoRatio() { if ($this->_photoWidth > $this->_photoHeight) { $maximumHeight = $this->_thumbHeight; $photoRatio = $maximumHeight / $this->_photoHeight; } elseif ($this->_photoWidth < $this->_photoHeight) { $maximumWidth = $this->_thumbWidth; $photoRatio = $maximumWidth / $this->_photoWidth; } else { $photoRatio = 1; } return $photoRatio; } /** * Method to create a new image. */ public function createNewImage($type, $source, $destination) { switch ($type) { case 1: if (function_exists('imagegif')) { imagegif($source, $destination); } else { imagejpeg($source, $destination, 50); } break; case 2: imagejpeg($source, $destination, 100); break; case 3: imagepng($source, $destination); break; } } } The php.ini file... Code: [Select] file_uploads on upload_max_filesize = 150M post_max_size = 150M max_input_time = -1 max_execution_time = 0 memory_limit = 150M register_argc_argv = false Hi all, I have been looking at thumbnail scripts and they are all very advanced for what I want. I just want to take 3 uploadeed jpg images, save a copy in original format and save a copy in images/thumbs/ with a size of 200px x 133px. Could someone just show me who to do this? Thanks The script I have for uploading the actual image is: <?php $destination='aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); $destination2='aircraft/'.$reg."2.jpg"; $temp_file2 = $_FILES['image2']['tmp_name']; move_uploaded_file($temp_file2,$destination2); $destination3='aircraft/'.$reg."3.jpg"; $temp_file3 = $_FILES['image3']['tmp_name']; move_uploaded_file($temp_file3,$destination3); ?> // Create the target image if ( function_exists('imagecreatetruecolor') ) { $targetImage = imagecreate($width, $height); } else { $targetImage = imagecreate($width, $height); } if ( ! is_resource($targetImage) ) { user_error('Cannot initialize new GD image stream', E_USER_NOTICE); return false; } // Copy the source image to the target image if ( $options['method'] == 2 ) { $result = imagecopy($targetImage, $sourceImage, 0, 0, $X, $Y, $W, $H); //imagejpeg($targetImage, $savePath . ( $filename = uniqid() . time() . '.jpg' ) ); } elseif ( function_exists('imagecopyresampled') ) { $result = imagecopyresampled($targetImage, $sourceImage, 0, 0, $X, $Y, $width, $height, $W, $H); //imagejpeg($targetImage, $savePath . ( $filename = uniqid() . time() . '.jpg' ) ); } else { $result = imagecopyresized($targetImage, $sourceImage, 0, 0, $X, $Y, $width, $height, $W, $H); //imagejpeg($targetImage, $savePath . ( $filename = uniqid() . time() . '.jpg' ) ); } if ( ! $result ) { user_error('Cannot resize image', E_USER_NOTICE); return false; } // Free a memory from the source image imagedestroy($sourceImage); // Save the resulting thumbnail return $targetImage; } creates thumbnail with black backround like this but white is needed. what to add and where ? Hi, I was curious if there is anyway to create website screenshots on the fly via a php script. Thanks, dilbertone - the first dilbert on earth Hi all Let me start by saying I'm a noob - who is trying to sort (order) the displayed thumbnails from the script below. I've read the sort, explode, scandir and array manuals - but every attempt fails. I've been reading for days.. and still nothing. I got the script from the net.. While researching how to make this work, I found someone else using the same script needing help on your forums... (http://www.phpfreaks.com/forums/index.php/topic,299137.0.html) I've changed mine a little to work with the directories, and added Javascript for displaying the clicked thumb, in place. The entire thing works like a charm, and displays the generated thumbs and so on - its just that when it comes out on the page, it's in a random order like 2.jpg, 3.jpg, 1.jpg. (It always seems to display the first photo last.) I'd like it to display 1.jpg, 2.jpg, 3.jpg so they appear in order on the page. This way I can group black and white photos from color photos in the same category, or show photos in the order they happened on a vacation for instance. Thanks in advance for any insight! <?php $columns = 5; $thmb_width = 120; $thmb_height = 80; function resizeImage($originalImage,$toWidth,$toHeight){ list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; 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)); } $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } function generateThumbnails(){ global $thmb_width,$thmb_height; if ($handle = opendir("/full/path/to/images/galleryname/")) { while ($file = readdir($handle)) { if (is_file($file)){ if (strpos($file,'_th.jpg')){ $isThumb = true; } else { $isThumb = false; } if (!$isThumb) { $dirName = substr($file,0,strpos($file,basename($file))); if (strlen($dirName) < 1) $dirName = '.'; $fileName = basename($file); $fileMain = substr($fileName,0,strrpos($fileName,'.')); $extName = substr($fileName,strrpos($fileName,'.'), strlen($fileName)-strrpos($fileName,'.')); if (($extName == '.jpg') || ($extName == '.jpeg')){ $thmbFile = $dirName.'/'.$fileMain.'_th.jpg'; if (!file_exists($thmbFile)){ imagejpeg(resizeImage($file,$thmb_width,$thmb_height) ,$thmbFile,80); }}}}}}} function getNormalImage($file){ $base = substr($file,0,strrpos($file,'_th.jpg')); if (file_exists($base.'.jpg')) return $base.'.jpg'; elseif (file_exists($base.'.jpeg')) return $base.'.jpeg'; else return ""; } function displayPhotos(){ global $columns; generateThumbnails(); $act = 0; $img_dir = 'images/galleryname/'; if ($handle = opendir($img_dir)) { while ($file = readdir($handle)) { if (strpos($file,'_th.jpg')){ ++$act; if ($act > $columns) { echo '<li><a onclick="return showPic(this)" href="'.getNormalImage($img_dir.$file).'"><img src="'.$img_dir.$file.'" alt="'.$file.'"/></a></li>'; }}}}} ?> <script type="text/javascript" language="javascript"> function showPic (whichpic) { if (document.getElementById) { document.getElementById('placeholder') .src = whichpic.href; if (whichpic.title) { document.getElementById('desc') .childNodes[0].nodeValue = whichpic.title; } else { document.getElementById('desc') .childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; } return false; } else { return true; } }</script> <div class="galthumbs"><ul> <?php displayPhotos(); ?> </ul></div> <div class="galmain"><img id="placeholder" src="images/galleryname/1.jpg" alt="" /></div><p id="desc"> </p> Hi i am using a script to upload an image and resize it twice first to create the large image and then again to create a thumbnail. The large image is being created fine and is uploading ok. I'm using the following code to then make the thumbnail but it does not appear to be working ( well nothing is in the thumbnail image folder i expect it to be anyways) can anyone see anything obvious that i am doing wrong ? Many Thanks /////////////////////////// Create a Thumbnail of the Image //////////////////////////////////// list($width, $height) = getimagesize($upload_image); // this is the large image which has apready been uploaded $ratio = $height/$width; if($ratio >= '1') // portret { $ht_tmb = 150; $br_tmb = 150/$ratio; } else { // landscape $ht_tmb = 150*$ratio; $br_tmb = 150; } // create thumb $source = imagecreatefromjpeg($upload_image); // The large image already uploaded //--- resize uploaded file $resize = imagecreatetruecolor($br_tmb, $ht_tmb); imagecopyresized($resize, $source, 0, 0, 0, 0, $br_tmb, $ht_tmb, $width, $height); imagejpeg($resize, "gallery_images/small/" .$filenamefd); $image = imagecreatefromjpeg("gallery_images/small/" .$filenamefd); imagejpeg($image, "gallery_images/small/" . $filenamefd); // end of making thumb ///////////////////////////////////////////////////////////////////////////////////////////////// I would be needing different picture sizes on different pages on my site but saving different sizes of a single pic is space consuming. I've heard that it's possible to automatically adjust the size of the picture and found a script that ought to make that possible. Unfortunately, it did not work for me. Article: PHP Thumbnail Script Using GD http://www.rainbodesign.com/pub/thumbnails/ Here's the code: Code: [Select] <? // Rainbo Design PHP Thumbnail Maker // Copyright (C) 2005-2010 by Richard L. Trethewey - rick@rainbo.net // All Rights Reserved // If you use this script, I'd appreciate a link! // http://www.rainbodesign.com/pub/ // Defaults $thumbsize = 150; // Default thumbnail width. $imagesource = 'images/default_img.jpg'; // Default image file name. // Set to empty string for no image output on failure. $error = ''; if (isset($_GET['width'])) { $thumbsize = $_GET['width']; } if (isset($_GET['src'])) { $imagesource = $_GET['src']; } $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if (file_exists($imagesource)) { if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); $imagewidth = imagesx($image); $imageheight = imagesy($image); if ($imagewidth >= $thumbsize) { $thumbwidth = $thumbsize; $factor = $thumbsize / $imagewidth; $thumbheight = floor($imageheight * $factor); } else { $thumbwidth = $imagewidth; $thumbheight = $imageheight; $factor = 1; } // Create a thumbnail-sized GD Image object $thumb = @imagecreatetruecolor($thumbwidth,$thumbheight); // bool imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h ) imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight); // Send output to user as a jpeg type, regardless of original type header("Content-type:image/jpeg;"); imagejpeg($thumb); imagedestroy($image); imagedestroy($thumb); } else { $error = "File $imagesource Not Found"; } // endif file_exists if ($error != '') { header('Content-type:text/plain;'); echo($error); exit; } // endif $error ?> And here's a little instruction (which I have followed as well). Quote All it takes is replacing the "src" parameter in the <img> tag with the URL for the PHP script, including the parameters "src" which contains the path to the original image file, and "color" to select the color for the font. The script also supports a "width" parameter to specify the width of your thumbnail image. Using that script to display the above image as a thumbnail by setting the "src" attribute to "makeThumb.php?src=slides/slide1.jpg", we get the resulting image shown on the right. Can anyone please help me with this script or something similar? Thanks in advance. ^_^ Edit: The problem is that the image is not showing. It appears as if it cannot locate the file source. hi all I am finishing off the final touches to my PHP postcard script and want to be able to display thumb file types only I have found a script to resize the images but this creates larger ones so i want to be able to switch between the two. <?php // CHANGE PARAMETERS HERE BEGIN $senderName = " Holidays From Home "; // Eg.: John's Postcards $senderEmail = "holidaysfromhome@voluntary.awardspace.co.uk"; // Eg.: john@postcard.com // Change only if you have problems with urls $postcardURL = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]; // CHANGE PARAMETERS HERE END $result = 0; $msg = ""; $msg1 = ""; $pic = ""; function displayPhotos() //edit photos and change image sizes { global $pic; $columns = 5; $act = 0; $act1 = 0; $sel = 0; // Open the actual directory if($handle = opendir("thumbs")) { // Read all file from the actual directory while($file = readdir($handle)) { if(!is_dir($file)) { if(isset($pic[1])) { if($pic[1] == $act1){$sel = "checked";} else{$sel = "unchecked";} } if($act == 0){echo "<tr>";} echo "<td align='center'><img src='thumbs/$file' alt='postcard' BORDER =1 /><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>"; //displays the images $act++; $act1++; if($act == $columns){$act = 0;echo "</tr>";} } } echo "</tr>"; } } ?> my thumbnail images all end in (_th.jpg) and my large files all end in (.jpg). I am really stuck any help would be much appreciated Hi! my code uploads an image and saves it to an upload folder, but I want to create a thumbnail of it. For example, if I upload a 1400x1000 JPG, I would like to resize the image and it has to respect the proportion given a maximum size. if I say the maximum width/height is 250px, the image should be thumbnailed according to the max height/width, and in proportion with the width/height Thanks in advance Fernando hi, i am trying to generate image gallery. but the problem is that when i upload the png files its thumbnail is generated with black background. JPEG an GIF thumbnail are generated successfully. i want to make background transparent. is there any solution that how i can get rid of it. i am using imagecreatetruecolor($thumbwidth, $thumbheight ); to generate thumbnail Hi, I have a script that uploads an image to a directory and then saves the fill path to a field in a table for later use. The only problem is people are uploading huge images and then when I produce a catalogue of my listings it takes forever to load because the images are so big. What I am after is an add in script to create an ADDITIONAL image 100 x 75px, I don't really want to change my upload script. Any ideas? Thanks in advace. Here is what I have: Code: [Select] <?php $idir = "../fleet/"; // Path To Images Directory if (isset ($_FILES['fupload'])){ //upload the image to tmp directory $url = $_FILES['fupload']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload']['name'], '$account.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload']['tmp_name'], "$idir" . $_FILES['fupload']['name']); // Move Image From Temporary Location To Perm } } $fleetimage1 = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']); //then insert sql code below... ?> Hey, I want to be able to have a 100x100 thumbnail of pictures I am uploading while cropping the image to maintain the ratio. Right now I am stretching the image and it looks bad but it works. Here is my code... Quote $new_thumb = "$new_pic"; $sourcefile = "$target2$pic"; $picsize = getimagesize("$target2$pic"); $source_x = $picsize[0]; $source_y = $picsize[1]; $dest_x = 100; $dest_y = 100; $targetfile = "$thumbs$pic"; $pathtofile = pathinfo($sourcefile); $extension = $pathtofile['extension']; $jpegqual = 75; if($extension=='jpg' || $extension=='jpeg' || $extension=='JPG') { $source_id = imagecreatefromjpeg("$target2$pic"); $target_id = imagecreatetruecolor($dest_x, $dest_y); $target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y); imagejpeg($target_id,"$targetfile",$jpegqual); } if($extension=='gif') { $source_id = imagecreatefromgif("$target2$pic"); $target_id = imagecreatetruecolor($dest_x, $dest_y); $target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y); imagegif($target_id,"$targetfile",$jpegqual); } if($extension=='png') { $source_id = imagecreatefrompng("$target2$pic"); $target_id = imagecreatetruecolor($dest_x, $dest_y); $target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y); imagepng($target_id,"$targetfile",$jpegqual); } How could I change this to make the thumbnails maintain the aspect ratio but still be 100x100? I have a form where you can enter a image url and it's title. It calls display.php which displays the image as well as the title. But I want the image to be displayed as a thumbnail of size 150X100. Do i have to store it in directory before I convert it and display? If so, can somebody tell me how to convert the image into a thumbnail? Here is my code: Code: [Select] <table align="center" bgcolor="silver"> <form action="display.php" method ="post"> <tr> <td align="center"><b><font color="#214754" size="3">Reg</font></b></td> </tr> <tr> <td> Title: </td> <td><input type="text" size ="40" name="registry_title1" /></td> </tr> <tr> <td> Image URL: </td> <td><input type="text" size ="40" name="registry_img1" /></td> </tr> <tr> <td> <input type="submit" name="submit" value="submit" /> </td> </tr> </form> </table> </div> here is the code for display.php Code: [Select] <? /* Get Registry details */ $registry_img1=$_POST['registry_img1']; $registry_title1=stripslashes($_POST['registry_title1']); ?> <html> <body> <table width='600' cellspacing='0' cellpadding='0' border='0' bgcolor='#ffffff' align='center'> <tr> <td style='padding-bottom:8px';><font style='font-size:18px;color:rgb(0, 0, 0);text-decoration:none'><a style='font-size:18px;color:rgb(0, 0, 0);text-decoration:none' href='#'><? echo ucfirst($url); ?> Registry</font></a></td> </tr> <tr> <td style='padding-bottom:10px;'> <a style='color:rgb(206, 0, 0);font-size:14px;font-weight:bold;line-height:18px;text-decoration:none' href='<? echo $registry_url1; ?>' target='_blank'><img style='padding-right:10px' border='0' align='left' alt='' src='<? echo $registry_img1; ?>'><? echo $registry_title1;?> </a> </td> </table> </body> </html> |