...

View Full Version : GD 1.6 Compatible Scripts



Candrias77
09-16-2003, 03:19 AM
Hi there, I have put together a script that works perfectly on my localhost which is running GD 2 but my host is running GD 1.6 and my code is not working at all!

The code below is roughly what I am using:



function resize_jpeg($image_file_path, $new_image_file_path, $max_width=500, $max_height=500)
{
$return_val = 1;

$return_val = ( ($img = ImageCreateFromJPEG ( $image_file_path )) && $return_val == 1 ) ? "1" : "0";

$FullImage_width = imagesx ($img); // Original image width
$FullImage_height = imagesy ($img); // Original image height

// check for over-sized images and scale them down
$ratio = ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
$new_width = ((int)($FullImage_width * $ratio)); //full-size width
$new_height = ((int)($FullImage_height * $ratio)); //full-size height
//check for images that are still too high
$ratio = ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
$new_width = ((int)($new_width * $ratio)); //mid-size width
$new_height = ((int)($new_height * $ratio)); //mid-size height

// --Start Creation, Copying--
// now, before we get silly and 'resize' an image that doesn't need it...
if ( $new_width == $FullImage_width && $new_height == $FullImage_height )
copy ( $image_file_path, $new_image_file_path );

$full_id = ImageCreateTrueColor( $new_width , $new_height ); //create an image
ImageCopyResampled( $full_id, $img,
0,0, 0,0, //starting points
$new_width, $new_height,
$FullImage_width, $FullImage_height );
$return_val = ( $full = ImageJPEG( $full_id, $new_image_file_path, 85 )
&& $return_val == 1 ) ? "1" : "0";
ImageDestroy( $full_id );
// --End Creation, Copying--

return ($return_val) ? TRUE : FALSE ;
}


What parts am I going to need to change to make it compatible?

Thanks a lot for your help.

Íkii
09-16-2003, 10:33 AM
ImageCreateTrueColor and ImageCopyResampled are both gd2+, replace with ImageCreate and ImageCopyResized - will destroy the quality though.

If you can create true colour images from ImageCreateFromJPEG calls (there are some builds that cannot even do that) you could use the trick detailed http://www.sitepoint.com/article/937[/b] (][b).

Your best bet though is to tell your host to upgrade - it is seriously in their best interests as the memory leaks in builds prior to 2 can get nasty - tell them Íkii reccommends 2.0.4 / 2.0.9 or 2.0.15 as the best of the post 2.0 bunch.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum