Page 1 of 1

Resize Image Problem

Posted: Thu Jul 01, 2004 1:03 pm
by tahlenius
I was wondering if anyone had experienced a problem with the resize image class, I have had the pictures when resized get a dark blue, or a hazy gray color to them. The picture format is JPG, and nothing about the types of pictures has changed. Please advise.

Thanks

Tim
tahlenius@reusserdesign.com

Posted: Thu Jul 01, 2004 1:14 pm
by feyd

Posted: Thu Jul 01, 2004 1:30 pm
by tahlenius
yes the jpeg convertion quality was bad, image is fine before entering the resize functions class

Posted: Thu Jul 01, 2004 1:35 pm
by feyd
are you aware that was a link?

Posted: Thu Jul 01, 2004 1:50 pm
by tahlenius
The following is the code that I have for resizing images right now. Please let me know if you see any problems that may lead to the color changes. I am looking into the link that you posted earlier.

Code: Select all

<?php
/* 
* resize_jpeg takes in a local image and outputs a smaller copy. 
* you send the full unix path, including filename, to the local 
* image (a relative path will work, too, just not as reliably), 
* the full path to the new, smaller image, and the maximum width 
* and height you'd like the image to be constrained within. 
* the script will not distort the image at all, except for the 
* standard degradation of the image through resizing. 
* returns TRUE or FALSE 
* 
* ex: resize_jpeg ( "/home/allah/images/blah.jpg", "/home/allah/images/small_blah.jpg", 300 ); 
* ex: resize_jpeg ( "../images/yikes.jpg", "../images/800x800_yikes.jpg", 800, 800 ); 
*/ 
function resize_jpeg( $image_file_path, $new_image_file_path, $max_width=480, $max_height=1600 ) 
{ 
     
    $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 
     
            // now we check for over-sized images and pare them down 
            // to the dimensions we need for display purposes 
    $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 Full 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 = ImageCreate( $new_width , $new_height );        //create an image 
    ImageCopyResized( $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, 80 ) 
                 && $return_val == 1 ) ? "1" : "0"; 
    ImageDestroy( $full_id ); 
            // --End Creation, Copying-- 
     
    return ($return_val) ? TRUE : FALSE ; 
     
} 

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

?>

feyd | use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Jul 01, 2004 4:26 pm
by scorphus
Did you follow the link feyd suggested:
Goodfella redmonkey, in a reply to another topic named [url=http://forums.devnetwork.net/viewtopic.php?p=111706#111706]hmm... jpeg convertion quality was bad!!![/url] of this very forum, wrote:Have you read the FAQs over on the GD site? (I suspect not). The short of it is that if you are using GD2 then you should be using the imagecreatetruecolor() function and not the imagecreate() function.
You could try this first.

Regards,
Scorphus.