Page 1 of 1

I can't resize images with gd, phpinfo says its installed..

Posted: Tue Apr 08, 2003 11:09 pm
by s3rg1o
Ok guys, I am trying to resize an image with GD and..it's not working..as if PHP is not recognizing the GD functions even though phpinfo says it's there:

gd
GD Support enabled
GD Version 2.0 or higher
JPG Support enabled
WBMP Support enabled

(that's copied from the phpinfo print out)


this is my code:

Code: Select all

<?



imagecopyresized(/home/web/pcgs/finish.jpg, /home/web/pcgs/062.jpg, 0 , 0 , 0 , 0, 150, 113, 1024, 768); 




?>
at first I thought I did something wrong then I just put imagecopyresized()

and no errors came out... any ideas guys..

Posted: Wed Apr 09, 2003 12:06 am
by volka
int imagecopyresized ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) takes ressource ids as parameters, not paths.
try

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE); // debug-settings
$resultFile = '/home/web/pcgs/finish.jpg';
$dWidth = 150;
$dHeight = 113;
$dst=imagecreate($dWidth, $dHeight);
$src=imagecreatefromjpeg('/home/web/pcgs/062.jpg'); 
imagecopyresized($dst, $src, 0 , 0 , 0 , 0, $dWidth, $dHeight, imagesx($src), imagesy($src));
imagejpeg($dst, $resultFile);
?>

Posted: Wed Apr 09, 2003 12:31 am
by s3rg1o
damn it..still no go! what is wrong with this...


I did a simple drawing script to test if I could at least draw, and I could

Code: Select all

<?
Header("Content-Type: image/jpeg");
$im = ImageCreate(500, 1000);
$red = ImageColorAllocate($im, 255, 0, 0);
ImageFill($im, 100, 100, $red);
ImageJPEG($im);
?>
and I could, it worked, but I can't resize...? I am pretty sure permissions are set too.

Posted: Wed Apr 09, 2003 4:46 am
by pootergeist
you are resizing from 1024x768 to 150x113 ?

the first thing you'd want to do is to create one image at 150x113 using the
$thum = imagecreatetruecolor(150,113);
syntax

then you want to create a copy of your resource image with maybe
$reso = imagecreatefromjpeg('image.jpg');

then you copy resource (now called $reso) onto thumbnail (called $thum) with a size change
imagecopyresampled( $thum, $reso, 0, 0, 0, 0, 150, 113, 1024, 768);

now $thum looks like a small copy of $reso - so you output it

imagejpeg($thum, 'thumbs/image.jpg', 85);
85% compression is pretty good for thumbs imo.

If you are feeling daring and want to take your thumbnailing a step further - try downloading the class I wrote at - http://www.phpclasses.org/browse.html/package/1007.html
and follow the comment suggestions. Does all the hard work for you and can also do drop_shadow, bevel, ellipse, merge, greyscale, motion_blur and more.

Subnotes:
GD2+ allows use of truecolour jpeg and png images, so you'd always want to use imagecreatetruecolor and imagecopyresampled in place of imagecreate and imagecopyresized (the latter two only support palette images - ie 256 colour)
the class I linked is 'specially designed for GD2+ :)

Posted: Wed Apr 09, 2003 4:37 pm
by s3rg1o
hrmm I'll work with it, I think I know what the problem was but I am going to format and installed redhat 9 today, are there any significant resize speed changes from GD 2.0.1 to GD 2.0.12 as I will just use php's native GD support, I know that updates like 2.0.12 have anti-aliasing support but I just wanted to know if there was a speed increase