|
|
 |
FN-FORUM: Creating thumbnails
date posted 9th March 2006 17:09
Hello All,
I have built an image library application (PHP/MySQL) which customers
use to upload pics to their sites within their CMS. It has a function
thumbnail() (see code below) which converts the full-size image to a
thumbnail for showing in the "gallery" view. The function uses NetPBM
tools to do the image manipulation.
I'm in the process of moving all my sites to a new server. The new
server doesn't have NetPBM tools installed, but it does have the GD
library. However I have read that GD does not support gif:
>> (gd does not support GIF anymore, because the packing algorithm in
>> GIF is copyrighted).
Obviously my customers will want to use gif.
Any idea how to get around this?
Best regards,
Ray
------------------------------
Ray McGinty Information Design
Specialising in web application development,
e-commerce and design for print.
http://www.rmid.co.uk
Listed on the National Business Link Consultants Register
> /*
> * The thumbnail function uses the pnmscale program from
> * the popular Netpbm image manipulation tools package
> * to create a thumbnail of the given image. If a thumbnail
> * already exists for the image, the function simply returns.
> * Script amended to create thumbnail even where one already exists.-
> RM 2.8.02
> */
> cfunction thumbnail($filename) {
>
> global $x_dim;
> global $y_dim;
> global $images_folder;
> /* Define where to find the various external binaries we need
> */
> $djpeg = "/usr/bin/djpeg"; /* decompresses a jpeg to ppm
> */
> $cjpeg = "/usr/bin/cjpeg"; /* compreses a ppm to jpeg format */
> $pnmscale = "/usr/bin/pnmscale"; /* scales a ppm image */
> $giftopnm = "/usr/bin/giftopnm"; /* convert a gif to ppm */
> $ppmtogif = "/usr/bin/ppmtogif"; /* convert a ppm to gif */
> $ppmquant = "/usr/bin/ppmquant"; /* colour quantize a ppm */
>
> $tdir = dirname($filename)."/thumbnails"; /* thumbnail
> directory */
>
> if(!filetype($tdir)) {
>
> // echo "Creating thumbnails directory \$tdir $tdir ";
> [EMAIL REMOVED] {
> echo "Unable to create $tdir dir - check
> permissions\n";
> return;
> }
>
>
> }
> $tfile = $tdir."/".basename($filename); /* thumbnail file
> */
>
> // if(!filesize($tfile)) {
> if(eregi("\.gif$",$filename)) { /* Look for .gif
> extension */
> exec("$giftopnm $filename | $pnmscale -xysize $x_dim $y_dim ".
> "| $ppmquant 256 | $ppmtogif -interlace >
> $tfile");
>
> } elseif(eregi("\.jpe?g",$filename)) { /* Look for .jpg or
> .jpeg */
> exec("$djpeg $filename | $pnmscale -xysize $x_dim $y_dim | ".
> "$cjpeg -outfile $tfile");
>
> } else { /* not a GIF or JPG file */
> return("");
> }
> // }
> return($tfile);
> }
|
 |
|