Yeah sorry about that.. It happens where I just hit reply and forget to add
the mail list address :-(

Oops.. hehe
------oOo---------------oOo------

 Julien Bonastre [The_RadiX]
 The-Spectrum Network CEO
 [EMAIL PROTECTED]
 www.the-spectrum.org

------oOo---------------oOo------
----- Original Message -----
From: "Kjell Hansen" <[EMAIL PROTECTED]>
To: "-=| Julien Bonastre |=-" <[EMAIL PROTECTED]>
Sent: Tuesday, September 24, 2002 1:55 AM
Subject: Re: [PHP] Create Thumbnails from image


Hey Julien!
Thanx for the code! Your posting from yesterday helped me out. Actually I
was on the right path all along but hadn't activated the GD-extension in my
php.ini and so I just got errors and grew _pretty_ annoyed by it. Then after
I got your message from yesterday giving med the same errors I realized that
there were somethin' cookin'. After activating the GD-extension and
restarted Apache your snippet worked fine and eventually mine too.

Thanx again for your effort, it would have been better though if we all had
sent this to the newsgroup. More people would have had a chance to see it
there...

Have fun
Regards
Kjell

----- Original Message -----
From: "-=| Julien Bonastre |=-" <[EMAIL PROTECTED]>
To: "Kjell Hansen" <[EMAIL PROTECTED]>
Sent: Monday, September 23, 2002 4:20 PM
Subject: Re: [PHP] Create Thumbnails from image


> OMG..
>
> This is the second question tonight I answer that I was just working on
> today :-p
>
> hah..
>
>
> Ok.. simple.. here's my code I used today for
www.operation-scifi.com/lobby
>
>
> Thing is.. It's about as understandable to other's as hieroglyphics..
>
> Therefore.. a simple solution..
>
> do this:
>
> <?
> header("Content-type: image/jpeg");
> $img=imagecreatefromxxx("../dir/img.ext"); //where xxx = jpeg | png | gif
> etc..
> $img2=imagecreate(150,100);
> $imgsize=getimagesize("../dir/img.ext");
> imagecopyresized($img2,$img,0,0,0,0,150,100,$size[0],$size[1]);
> imagexxx($img2);
> ?>
>
> Substitute the filepath etc.. and also the 150/100 dimension sizes..
>
> xxx denotes the image type which depending on your GD version .. jpeg has
> always been supported.. GIF has been removed as of 1.6 I think due to the
> LZW compression patent by Unisys.. and now they have PNG which my site
uses
> due to it's much better file format and flexibility..
>
> Also BTW.. this script is designed to be a seperate file.. ie image.php
>
> perhaps even do what I did and make the filename actually a $_GET param..
>
> As in.. you call: ./image.php?im=whatever.jpg
>
> and it generates a thumbnailed version..
>
> if your using JPEG format you can also use this param in the
> imagejpeg($img2); function:
>
> imagejpeg($img2,"",80); whereby the output quality is no 80%.. that means
> lower qual thumbnail..
>
> There is a lot of fun things that can be done just with the core graphics
> module of PHP without GD.
>
> but GD is soo great it can do much more exciting things..
>
> Like for instance today I wanted to resize these big pics.. That's all
> good.. But they are somewhat pixellised from the large downshrink. Now..
the
> function imagecopyresample() would be great..
>
> but's a GD2+ thing.. I don't use GD plus yet.. [downloading the bin as I
> write this] but that's just one great func. taht allows for resize and
> interpolation of near pixels (ie smoothing)..
>
> w00tage eh??
>
>
> Anyways.. enough said. rambling on now.. HIH
>
>
>
> /***** IMAGE HANDLING ROUTINE *****/
>
>   $errmsg=Array();
>   if(strlen($_GET["d"])<1) {
>     $errmsg[]="Invalid GET params sent:";
>     $errmsg[]="Must send valid data_id to script!";
>
>
$fwidth=(strlen($errmsg[count($errmsg)-1])>$fwidth?strlen($errmsg[count($err
> msg)-1]):$fwidth);
>   } else {
>     $sql=mysql_query("SELECT * FROM opscifi_news_data WHERE data_id =
> ".$_GET["d"],$DB);
>     if(mysql_num_rows($sql)>0 AND $ditem=@mysql_fetch_array($sql)) {
>
>
if(!file_exists("./news/n".$ditem["news_id"]."d".$ditem["data_id"].".".subst
>
r($ditem["filename"],strpos($ditem["filename"],".",0)+1,strlen($ditem["filen
> ame"])-(strpos(fname,".",0)+1)))) {
>         $errmsg[]="Invalid file request:";
>         $errmsg[]="File
>
./news/n".$ditem["news_id"]."d".$ditem["data_id"].".".substr($ditem["filenam
>
e"],strpos($ditem["filename"],".",0)+1,strlen($ditem["filename"])-(strpos(fn
> ame,".",0)+1))." does not exist!";
>
>
$fwidth=(strlen($errmsg[count($errmsg)-1])>$fwidth?strlen($errmsg[count($err
> msg)-1]):$fwidth);
>       } elseif(!preg_match("/(jpg|jpeg|jpe)/i",$ditem["filename"])) {
>         $errmsg[]="Invalid image type request:";
>         $errmsg[]="Script can only process image/jpeg files!";
>
>
$fwidth=(strlen($errmsg[count($errmsg)-1])>$fwidth?strlen($errmsg[count($err
> msg)-1]):$fwidth);
>       } else {
>       // Spit out required [standard] MIME-type header
>         header("Content-type: image/jpeg");
>       // Fetch the "original" friendly filename
>         $row=mysql_fetch_array(mysql_query("SELECT filename FROM
> opscifi_news_data WHERE data_id = ".$_GET["d"],$DB));
>         $ditem["filename"]=$row[0];
>         header("Content-Disposition: image;
filename=".$ditem["filename"]);
>
>       // Update request field in images "data" element
>         if(!isset($_GET["t"])) mysql_query("UPDATE opscifi_news_data SET
> requests = requests + 1 WHERE data_id = ".$_GET["d"],$DB);
>
>       // Load nxdx.ext into
>
>
$f="./news/n".$ditem["news_id"]."d".$ditem["data_id"].".".substr($ditem["fil
>
ename"],strpos($ditem["filename"],".",0)+1,strlen($ditem["filename"])-(strpo
> s(fname,".",0)+1));
>         $img=imagecreatefromjpeg($f);
>         $size=getimagesize($f);
>         if(isset($_GET["h"]) or isset($_GET["w"])) {
>
>
$outimg=imagecreate((isset($_GET["w"])?$_GET["w"]:$size[0]),(isset($_GET["h"
> ])?$_GET["h"]:$size[1]));
>           imagecopyresized($outimg, $img,
>
0,0,0,0,(isset($_GET["w"])?$_GET["w"]:$size[0]),(isset($_GET["h"])?$_GET["h"
> ]:$size[1]),$size[0],$size[1]);
>         } else {
>           $outimg=$img;
>         }
>         imageinterlace($outimg,1);
>         imagejpeg($outimg,"",(isset($_GET["q"])?$_GET["q"]:100));
>       }
>     } else {
>       $errmsg[]="News Data Item Not in 'news_data' table!";
>
>
$fwidth=(strlen($errmsg[count($errmsg)-1])>$fwidth?strlen($errmsg[count($err
> msg)-1]):$fwidth);
>     }
>   }
>
>   if(strlen($errmsg)>0) {
>   // Spit out required [standard] MIME-type header
>     header("Content-type: image/jpeg");
>     $f_size=2;
>
>
$img=imagecreate(imagefontwidth($f_size)*$fwidth+14,(imagefontheight($f_size
> )+2)*count($errmsg)+5);
>     imagefill($img, 0, 0, imagecolorallocate($img, 220,220,220));
>     foreach($errmsg as $pos=>$str) imagestring($img, $f_size, 7,
> 3+($pos*(imagefontheight($f_size)+2)), $str, imagecolorallocate($img, 255,
> 0, 0));
>     imageinterlace($img,1);
>     imagejpeg($img);
>     exit();
>   } else {
>     exit();
>   }
>
> ------oOo---------------oOo------
>
>  Julien Bonastre [The_RadiX]
>  The-Spectrum Network CEO
>  [EMAIL PROTECTED]
>  www.the-spectrum.org
>
> ------oOo---------------oOo------
>
> ----- Original Message -----
> From: "Kjell Hansen" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Monday, September 23, 2002 1:09 AM
> Subject: [PHP] Create Thumbnails from image
>
>
> > Hi,
> > I'm using a Win2k with php4.1 and I'd like to make some thumbnails from
> > pictures on my disk.
> > I've gotten the impression that it's possible, but I havent' found out
> > just how.
> >
> > I've stumbled across the ImageCopyResized function but it requires a
> > imagehandle(?) to the file copied from. How do I get that? Is it the
> > right way to do this?
> > I guess I could use some picture manipulating program to do this, but
> > doing it the PHP way is nicer :)
> >
> > TIA
> > Kjell
> >
> >
> > --
> > 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

Reply via email to