I have the following code to resize an image:
<?php
$image = $_GET['image'];
$max_height = $_GET['max_height'];
$max_width = $_GET['max_width'];
if (!$max_width) {
$max_width = 80;
}
if (!$max_height) {
$max_width = 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, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
header('content-type: image/jpeg');
ImageJpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);
?>
And then I call this script in the image tag:
<?php
$image1 = "my_image.jpg";
echo "<img src=\"image_resize.php?image=";
echo urlencode($image1);
echo "&max_width=100&max_height=100\"/>";
?>
This resizes the images okay but for some reason it makes them an odd colour? Has anyone any idea why this is?