SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    color loss when creating thumbnail

    Hi,
    I'm used the code below from Seanf (running with GD). It gave me thumbnail OK with full colors; but if I change $max_width = 120; and $max_height = 100 (since I want larger thumbnail), most colors in the image will be lost. What's to do?

    Thanks,
    John
    PHP Code:
    <?php

    $image 
    'coverr.jpg';
    if (!
    $max_width)
      
    $max_width 80;
    if (!
    $max_height)
      
    $max_height 60;

    $size GetImageSize($image);
    $width $size[0];
    $height $size[1];

    $x_ratio $max_width $width;
    $y_ratio $max_height $height;

    if ( (
    $width <= $max_width) && ($height <= $max_height) ) {
      
    $tn_width $width;
      
    $tn_height $height;
    }
    else if ((
    $x_ratio $height) < $max_height) {
      
    $tn_height ceil($x_ratio $height);
      
    $tn_width $max_width;
    }
    else {
      
    $tn_width ceil($y_ratio $width);
      
    $tn_height $max_height;
    }

    $src ImageCreateFromJpeg($image);
    $dst ImageCreate($tn_width,$tn_height);
    ImageCopyResized($dst$src0000,
        
    $tn_width,$tn_height,$width,$height);
    header("Content-type: image/jpeg");
    ImageJpeg($dstnull, -1);
    ImageDestroy($src);
    ImageDestroy($dst);

    ?>

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What version of GD are you using?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have the same problem , my dg if is :

    GD Support enabled
    GD Version 2.0 or higher
    FreeType Support enabled
    FreeType Linkage with freetype
    JPG Support enabled
    PNG Support enabled
    WBMP Support enabled


    from phpinfo.php !

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are have gd 2.0.1 you can use ImageCreateTrueColor()
    http://www.php.net/manual/en/functio...etruecolor.php

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thx i`ll try it !


Bookmarks

Posting Permissions

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