Forum Thread
  Posts  
jpg thumbnail creation in PHP using GDlib (Forums : Coding & Scripting : jpg thumbnail creation in PHP using GDlib) Locked
Thread Options
jacksonj04
jacksonj04 Over 9000
Apr 17 2003 Anchor

read the title, I've tried a few methods but I'm sure there's an easy way to generate a thumbnail from a PHP script (e.g. <img src="thumb.php?img=fullsize.jpg">)

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

Apr 21 2003 Anchor

Try for thumb.php?img=picturelocation&scale=0.5 (where 'scale' could be a spinkee scalerizer!):

&lt;?php
if(file_exists($img)) {} else { die(&quot;Image doesn&#039;t exist&quot;); }

$orig_image = imagecreatefromjpeg($img);  //takes your picture
$orig_x = imagesx($orig_image);
$orig_y = imagesy($orig_image); //size in pixels of original picture

$x = $orig_x * $scale;
$y = $orig_y * $scale;
//just replace $x,$y with values if thumbs are fixed size, e.g. 200x150 instead of 50% size
$sm_image = Imagecreate($x,$y); //creates a new blank thumbnail

Imagecopyresampled($sm_image,$orig_image,0,0,0,0,$x,$y,$orig_x,$orig_y);
//resizes the big pic and copies it into your blank thumbnail

Header(&quot;Content-type: image/jpeg&quot;); //so your browser knows it&#039;s a picture
imageJPEG($sm_image); //shows the picture itself
?&gt;

(I haven't tested this though!)
You might want to use an 'imagedestroy' command after too, but it's quicker to store thumbnails and recall than make them on the fly- have something like the above that automatically thumbnails pictures when you upload them via a form, or something. If that doesn't work, or you want something more advanced, I can send you a code sample when my website works again!

- Edited By Leperous On Mon 21st, Apr 2003 @ 11:14:07am

Apr 21 2003 Anchor

Wuggawoo.co.uk

O_o

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
Apr 25 2003 Anchor

it wooorks, except you really should ImageCreateTrueColor

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

Apr 25 2003 Anchor

Tada!

Wuggawoo.co.uk

--

Why wont it save me?

PsychoFarmer
PsychoFarmer modDB King
Apr 25 2003 Anchor

nifteh O_o

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.