hi. a script i edited works for jpegs, and only jpegs. will work on gifs and png as long as i ultimately convert them to jpgs. what im wondering is why it is not working for gifs and png files. here is the relevant code:

// Content type
if($extension == 'jpg' || $extension == 'jpeg'){
	header('Content-type: image/jpeg');
} else if($extension == 'gif') {
	header('Content-type: image/gif');
} else  if($extension == 'png'){
	header('Content-type: image/png');
}


// Resample
$image_p = imagecreatetruecolor($width, $height);
if($extension == 'jpg' || $extension == 'jpeg'){
	$image = imagecreatefromjpeg($file);
} else if($extension == 'gif') {
	$image = imagecreatefromgif($file);
} else  if($extension == 'png'){
	$image = imagecreatefrompng($file);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
if($extension == 'jpg' || $extension == 'jpeg'){
	imagejpeg($image_p, null, 80);
} else if($extension == 'gif') {
	imagegif($image_p, null);
} else  if($extension == 'png'){
	imagepng($image_p);
}

    I regret to inform you that... I tried that code and it works for me. 🙁 I can suggest two things:

    1) The gif and png files you used to test were invalid files.
    or
    2) There is something wrong with the GD Library you are using.

    ... or 3, I don't know, haha. 😃

      Um, 3) the value of $extension is wrong (how is this being determined? The reliable way to identify the format of an image is with getimagesize(). Everything else can be faked.)

      Another piece of information that would be helpful to know would be what output is produced if it's not an image like it's supposed to be.

        I figured it out. I'm actually loading the images into Flash, and I wasn't publishing as Flash 8. In earlier Flash versions, only jpgs and swfs are supported.

        Sorry, I probably should have mentioned that.

          Write a Reply...