Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GD 1.6 Compatible Scripts

    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:

    PHP Code:
    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" "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) : ;
        
    $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) : ;
        
    $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_path85 )
        && 
    $return_val == ) ? "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.
    eTheory - the theory of revolution

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    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.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •