Re: [PHP] Thumbnail generation
i want to generate the thumbnail of an image but I want my php to be portable. How can I generate thumbnail without depending on php host configuration (like --with-gd) ? Along with the othe suggestions, Netpbm is something that you can package up with your application so that you are always sure it's available to it. http://netpbm.sourceforge.net/ Better yet, take the time to write an Image Abstraction Layer that'll function just like a Database Abstraction Layer. You use the same functions no matter what and depending on the config, either GD, Imagemagik, Netpbm, or whatever is used to do the dirty work. Does anyone know of such a project or want to write one? ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Thumbnail generation
On Mon, 23 Dec 2002, 1LT John W. Holmes wrote: Better yet, take the time to write an Image Abstraction Layer that'll function just like a Database Abstraction Layer. You use the same functions no matter what and depending on the config, either GD, Imagemagik, Netpbm, or whatever is used to do the dirty work. Does anyone know of such a project or want to write one? Image_Transform in PEAR: http://pear.php.net/package-info.php?pacid=83 -- Mika Tuupola http://www.appelsiini.net/~tuupola/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Thumbnail generation
Hi all , i want to generate the thumbnail of an image but I want my php to be portable. How can I generate thumbnail without depending on php host configuration (like --with-gd) ? Thanks . Perseus _ The new MSN 8: smart spam protection and 3 months FREE*. http://join.msn.com/?page=features/junkmailxAPID=42PS=47575PI=7324DI=7474SU= http://www.hotmail.msn.com/cgi-bin/getmsgHL=1216hotmailtaglines_smartspamprotection_3mf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Thumbnail generation
Is there some common utilities recommended ? From: Rasmus Lerdorf [EMAIL PROTECTED] To: Centaur zeus [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [PHP] Thumbnail generation Date: Sun, 22 Dec 2002 21:07:35 -0800 (PST) You are going to have to depend on something. If you don't want to use GD, you are going to need some external mechanism which will have to be available. -Rasmus On Mon, 23 Dec 2002, Centaur zeus wrote: Hi all , i want to generate the thumbnail of an image but I want my php to be portable. How can I generate thumbnail without depending on php host configuration (like --with-gd) ? Thanks . Perseus _ The new MSN 8: smart spam protection and 3 months FREE*. http://join.msn.com/?page=features/junkmailxAPID=42PS=47575PI=7324DI=7474SU= http://www.hotmail.msn.com/cgi-bin/getmsgHL=1216hotmailtaglines_smartspamprotection_3mf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Thumbnail generation
On Monday 23 December 2002 14:26, Centaur zeus wrote: Is there some common utilities recommended ? ImageMagick -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* It's not easy, being green. -- Kermit the Frog */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Thumbnail Generation from DB Stored Images.
Here is my code to turn a directory full of *files* into thumbnail images. im sure you can adapt it to your own needs... the code is a bit long-winded, but it was my first attempt at writing thumbnail code, so forgive me ;) // example call to the function make_thumbs('./pictures/cavern/', './pictures/cavern/thumbs', 200, 60 ); /* Simple function to make thumbnail images for an entire directory of .JPG images. (no GIF support because the owners of the GIF patent are buttheads) It will create square thumbnail images (height=width), with the original image resized properly within the thumbnail dimensions to preserve the height to width ratio This code is free for use as long as you keep my email and URL in here: [EMAIL PROTECTED] [EMAIL PROTECTED] http://furt.com/code/make_thumbs/ Syntax of function call make_thumbs( $dir= where the original image files are located $tdir = where you want the thumbnails to be saved $max= $max=width=height of the new thumbnail images all thumbnails are square. $quality = quality of thumbnail JPG worst(1..100)best $border = how many pixels of border to put around the image ); */ function make_thumbs($dir, $tdir, $max, $quality=75, $border=3) { // this is so the script won't time out set_time_limit(0); $files = opendir($dir) or die(Cannot opendir $dir); while ($file = readdir($files)) { if ( preg_match(/[a-zA-Z0-9]\.(jpg|jpeg|JPG|JPEG)$/, $file) ) { //if (!file_exists($tdir .'/'. $file .'_t.jpg')) { // Information about the original image $img_name = $dir .'/'. $file; $img = imagecreatefromjpeg($img_name) or die(Cannot read $img_name); $img_x= $img_y = 0; $img_w= imagesx($img); $img_h= imagesy($img); // Create a new empty container for the thumbnail image $out = imagecreate($max, $max); // Set background colour of the thumbnail container $bg = ImageColorAllocate($out, 200,200,200); // If image is more wide than tall if ($img_w $img_h) { $mod = ($img_w - $max) / $img_w; $out_w = $max; $out_h = $img_h * (1 - $mod); $out_x = 0; $out_y = ($max - $out_h) / 2; $out_x += $border; $out_w -= $border*2; } // If image is more tall than wide else { $mod = ($img_h - $max) / $img_h; $out_h = $max; $out_w = $img_w * (1 - $mod); $out_y = 0; $out_x = ($max - $out_w) / 2; $out_y += $border; $out_h -= $border*2; } // for debugging purposes... so i can see what's going on //print out_x=$out_x, out_y=$out_y, img_x=$img_x, img_y=$img_y\n; //print out_w=$out_w, out_h=$out_h, img_w=$img_w, img_h=$img_h\n; //Put some text into the image //$fg = ImageColorAllocate($out, 0,0,0); //imagestring ($out, '2', 3, $max-15, Text, $fg); // Copy and resize the original image into the new thumbnail container imagecopyresized ( $out, $img, $out_x, $out_y, $img_x, $img_y, $out_w, $out_h, $img_w, $img_h); // Save the image to disk (in the thumbnail directory) imagejpeg($out, $tdir .'/'. $file .'_t.jpg', $quality); //} }#if }#while } -Original Message- From: Jason Bell [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 7:27 PM To: [EMAIL PROTECTED] Subject: [PHP] Thumbnail Generation from DB Stored Images. Hello! I have images stored in a MySQL Database. I can retrieve the images and display them without a problem, but I'd really like to be able to create thumbnails. The code that I've written just doesn't seem to work. Preferably, I'd like to pull the image from the database, and create the thumbnail for display, without ever writing an image to the disk. If this is not possible, I'd like to know alternate methods. I'm using imagemagick's convert utility to create the thumbs. Here is my code: getpic.php: ?php if($id) { @MYSQL_CONNECT(localhost,username,mypassword); @mysql_select_db(daelic); $query = select image,type from images where id=$id; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,image); $type = @MYSQL_RESULT($result,0,type); Header( Content-type: $type); echo $data; }; ? tgen.php: ?php
[PHP] Thumbnail Generation from DB Stored Images.
Hello! I have images stored in a MySQL Database. I can retrieve the images and display them without a problem, but I'd really like to be able to create thumbnails. The code that I've written just doesn't seem to work. Preferably, I'd like to pull the image from the database, and create the thumbnail for display, without ever writing an image to the disk. If this is not possible, I'd like to know alternate methods. I'm using imagemagick's convert utility to create the thumbs. Here is my code: getpic.php: ?php if($id) { @MYSQL_CONNECT(localhost,username,mypassword); @mysql_select_db(daelic); $query = select image,type from images where id=$id; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,image); $type = @MYSQL_RESULT($result,0,type); Header( Content-type: $type); echo $data; }; ? tgen.php: ?php if ($id) { $src = getpic.php?id=$id; $thumb = passthru(convert -geometry 40% $src jpeg:-); print $thumb; }; ? I know that getpic.php works. I can use it in like this: echo IMG SRC='getpic.php?id=$id'; and it will output the fullsize graphic in place. I'm trying to get to a point where I can use tgen.php in the same mannor. I can use the same convert command if I use an actual file, like pics/mypic.jpg and it works, so the command is good. any help at all would be very appreciated, Jason Bell
RE: [PHP] Thumbnail Generation from DB Stored Images.
Jason-- There are many reasons I don't quite recommend creating the thumbnails on the fly with ImageMagick: 1) I've heard many say that storing/retrieving images from MySQL databases isn't the greatest idea, because you end up with -huge- tables, which leads to long query times. 2) Resizing a JPEG on the fly is a very CPU intensive task 3) Calling the shell, then calling the ImageMagick program is more and more overhead. If you insist on storing the images in the database, then you're best off storing the thumbnails in there too. If you insist on creating thumbnails on the fly, then I suggest you install PHP 4.0.6 with GD 2.0.1 and use ImageCopyResampled() or ImageCopyResized() to do it-- it'll save you from spawning a shell and running an external program. I had to create a Real Estate site, where house listings could be posted with photos to accompany them... When a photo was uploaded (HTTP upload), the script would use ImageCreateTrueColor() to create two new images, then I called ImageCopyResampled() to resize the image to two different sizes-- one thumbnail for search results, then a larger one for listing details. I stored these images in a directory in the format: /images/1_thumb.jpg /images/1_full.jpg And so on... The number (1 in this case) corresponded with the auto_increment ID of the MySQL record for the item. When the listing is deleted, PHP deletes the associated images automatically (if they exist). Good luck! -Original Message- From: Jason Bell [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 7:27 PM To: [EMAIL PROTECTED] Subject: [PHP] Thumbnail Generation from DB Stored Images. Hello! I have images stored in a MySQL Database. I can retrieve the images and display them without a problem, but I'd really like to be able to create thumbnails. The code that I've written just doesn't seem to work. Preferably, I'd like to pull the image from the database, and create the thumbnail for display, without ever writing an image to the disk. If this is not possible, I'd like to know alternate methods. I'm using imagemagick's convert utility to create the thumbs. Here is my code: getpic.php: ?php if($id) { @MYSQL_CONNECT(localhost,username,mypassword); @mysql_select_db(daelic); $query = select image,type from images where id=$id; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,image); $type = @MYSQL_RESULT($result,0,type); Header( Content-type: $type); echo $data; }; ? tgen.php: ?php if ($id) { $src = getpic.php?id=$id; $thumb = passthru(convert -geometry 40% $src jpeg:-); print $thumb; }; ? I know that getpic.php works. I can use it in like this: echo IMG SRC='getpic.php?id=$id'; and it will output the fullsize graphic in place. I'm trying to get to a point where I can use tgen.php in the same mannor. I can use the same convert command if I use an actual file, like pics/mypic.jpg and it works, so the command is good. any help at all would be very appreciated, Jason Bell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]