<?php

//visit www.corehackers.com , 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);
ImageDestroy($src);
ImageDestroy($dst);

//by firstbase/corewizard from www.corehackers.com
?>
7
Contributors
6
Replies
7
Views
12 Years
Discussion Span
Last Post by chumsie
0

Hi,
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

0

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

0


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

0

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

I Hope so....

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.