I have tried numerous image resizing solutions and have not gotten any of them to work. All i want to do is resize multiple images as they are loaded on the page. I need to do this for a photo gallery page as well as a members page that has headshots of each member. Basically it might be used to resize up 10 images at a time.
Right now this is the script that I am using.
:::::: image_resize.php ::::::::::::::::::::::::::
::::::::::
:
#!/usr/local/bin/php4
<?php
$image = $HTTP_GET_VARS['image'];
if (!$max_width)
$max_width = 200;
if (!$max_height)
$max_height = 200;
$size = @getimagesize(rtrim($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;
$th_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($imag
e);
$dst = @ImageCreate($tn_width,$tn
_height);
@ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width, $tn_height, $width,$height);
header('Content-type: image/jpeg');
header("Content-Dispositio
n: inline; filename=generated.jpg");
ImageJpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);
?>
::::::::::::::::::::::::::
::::::::::
::::::::::
::::::::::
::::::::::
this is called from another page using
// db query
$photoName = mysql_result($result, $i,'photoPath');
// some more code
$image = '
https://www.xxxxx.xxx/~xxxx/upload/'.$photoName.'';
print '<img src=\'
https://www.xxxxx.xxx/~xxxx/image_resize.php?image='.$image.'\' height=\''.$height.'\' width=\''.$width.'\' border=\'1\'>';
One thing to note is that the images are coming from a secure server but the page they are displayed in is not. One other thing is that the site I am developing is for a unversity and they have massive restrictions on everything, none of which I have any control over. This has caused me more than one headache already. I am also a newbie to PHP and mySQL so I don't know too much. thanks
Start Free Trial