Candrias77
09-16-2003, 02: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.
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.