Re: GD Library and outputing image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ross escreveu:
....................
$image = imagecreatefromjpeg($img_url);

$image in this case, is the Image Identifier, and returns something like , Resource id #NUMBER ( Resourse id allocation process, for the generic imagecreate... ).

if ($image === false) { die ('Unable to open image'); }

// Get original width and height
echo $width = imagesx($image);
echo $height = imagesy($image);

// New width and height
$new_width = 200;
$new_height = 150;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);

$image_resized is another Image Identifier


imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

The imagecopyressampled() returns a boolean value [ TRUE(1) or FALSE(0)].
This value can be used to test the function success.

A) If you haven't no problem with readers, you must use:

> // Display resized image
> header('Content-type: image/jpeg');
> imagejpeg($image_resized);
imagedestroy($image);
imagedestroy($image_resized);

So, in this case you have 2 Image Identifiers, to be destroyd at the end, to freely the processes.

imagedestroy($image);
imagedestroy($image_resized);

B) However, if you have problems with header, you must use:

imagejpeg ($image_resized,  "image.jpg");
echo '<img src="image.jpg" border="0" alt="image.jpg" title="image" />';
imagedestroy($image);
imagedestroy($image_resized);

instead of
>
> // Display resized image
> header('Content-type: image/jpeg');
> imagejpeg($image_resized);
imagedestroy($image);
imagedestroy($image_resized);

die();
This is not allowed here.
-----------
Please see an example of imagecopyressampled() here:

http://www.educar.pro.br/en/a/gdlib/index.php?pn=20&tr=97


--
zerof
http://www.educar.pro.br/
Apache - PHP - MySQL - Boolean Logics - Project Management
----------------------------------------------------------
Você deve, sempre, consultar uma segunda opinião!
----------------------------------------------------------
Deixe todos saberem se esta informação foi-lhe útil.
----------------------------------------------------------	
You must hear, always, one second opinion! In all cases.
----------------------------------------------------------
Let the people know if this info was useful for you!
----------------------------------------------------------

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux