Resizing an image

corewizard 0 Tallied Votes 126 Views Share

this script, made by me, lets you resize an image propotionally!


//visit , a security portal

$image = $HTTP_GET_VARS['image'];

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 (($height <= $max_height) && ($width <= $max_width))
		$tn_height = $height;
		$tn_width = $width;
elseif (($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);
ImageCreateResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
header('Content-type: image/jpeg');
ImageJpeg($dst, null, -1);

//by firstbase/corewizard from
72dpi 11 Newbie Poster

Love it.. Just what i needed... =)

vanceibz 0 Newbie Poster

Im very new to php :) , this will sound stupid! where is the outcome? i trying to find the final result, that is put into a variable, I guess...

I have a simple HTML img tag:
<img src="image.jpg" width="74" height="50" border="0">

thanks for any help

mohamed badr 0 Newbie Poster

i used your code and it gave me the following error both locally and on the server
Call to undefined function ImageCreateResized

willjames 0 Newbie Poster


franx47 0 Newbie Poster

Warning: imagecreate() [function.imagecreate]: Invalid image dimensions in C:\xampp\htdocs\test\index.php on line 26

Fatal error: Call to undefined function imagecreateresized() in C:\xampp\htdocs\test\index.php on line 27

Image file : testimage.jpg

chumsie 0 Newbie Poster

I'm new with php and i want to try your code for our WEBPAGE project if it works

I Hope so....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.