note 51466 added to function.imagecreatefromjpeg

From: Date: Thu, 31 Mar 2005 14:13:51 +0000
Subject: note 51466 added to function.imagecreatefromjpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-87267@lists.php.net to get a copy of this message
This is a very useful script when you have hundreds of images and you need a quick setup for a thumbnail, where you can select how many pictures per row, size of the thumbnail, and the size of the pictures when clicked, all in one script. Just throw all your images and this script in a file named index.php or index.html (if your apache httpd.conf defaults to html and runs .html as php). Script also contains simple text watermarking. See function thumbImage() and modify to add image watermarking if you like. <? // 30 Minutes Thumbnail script written by Angel Leon from wedoit4you.com // Licensed under the GPL // Courtesy of wedoit4you.com //Instructions: //copy this script wherever you have a bunch of .jpgs // Invoke your thumbnail like this http://mysite.com/imageFolder/index.php //where index.php is this script. //Modify and redistribute but don't remove our trademark. //configure script here //pictures per row $row_size = 3; //height of the pictures in thumbnail $thumb_height = 200; //height of the pictures when clicked (to save bandwidth) $big_image_height=668; //short name of your site $waterMark = "mysite.com"; $dh = opendir("."); $files = array(); while (($file = readdir($dh)) !== false) { if (ereg("jpg",$file) || ereg("gif",$file) || ereg("png",$file)) { $files[] = $file; } } closedir($dh); if ($show_image) { thumbImage($show_image,$big_image_height,$waterMark); } else if ($thumb_image) { thumbImage($thumb_image,$thumb_height,$waterMark); } else { echo "<center>" . createThumbTable($files,$row_size) . "</center>"; } function createThumbTable($files,$pics_wide) { $row = intval(count($files)/$pics_wide); $picIndex = 0; $rs = "Mostrando " . count($files) . " imagenes<br>"; $rs .= "<table border=0 cellspacing=1 cellpadding=0 style='border:1px solid black'>\n"; for ($i=0; $i <$row; $i++) { $rs .= "\t<tr>\n"; for ($picIndex,$j=0; $j < $pics_wide && $picIndex < count($files); $j++,$picIndex++) { $rs .= "\t\t<td><a href=index.php?show_image=" . $files[$picIndex] . ">" . "<img src=index.php?thumb_image=" . $files[$picIndex] . " border=0 title='Copyright wedoit4you.com'></a></td>\n"; //$rs .= "<td>i=$i / $j=$picIndex</td>"; } $rs .= "\t</tr>\n"; }//for $rs .= "<tr><td colspan=$pics_wide align=center>Free Thumbnail script by <a href=http://www.wedoit4you.com>wedoit4you.com</a><br>Written by Angel Leon (March 2005)</td></tr></table>\n"; return $rs; } //createThumbTable function thumbImage($file,$img_height,$waterMark) { $img_temp = imagecreatefromjpeg($file); $black = @imagecolorallocate ($img_temp, 0, 0, 0); $white = @imagecolorallocate ($img_temp, 255, 255, 255); $font = 2; $img_width=imagesx($img_temp)/imagesy($img_temp)*$img_height; $img_thumb=imagecreatetruecolor($img_width,$img_height); imagecopyresampled($img_thumb, $img_temp,0,0,0,0,$img_width, $img_height, imagesx ($img_temp), imagesy($img_temp)); $originx = imagesx($img_thumb) - 100; $originy = imagesy($img_thumb) - 15; @imagestring ($img_thumb, $font, $originx + 10, $originy, $waterMark, $black); @imagestring ($img_thumb, $font, $originx + 11, $originy - 1, $waterMark, $white); header ("Content-type: image/jpeg"); imagejpeg($img_thumb, "", 60); imagedestroy ($img_thumb); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatefromjpeg.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51466 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51466&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51466&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51466&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51466&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51466&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51466&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87267) next »