0

I have images in the database, and I am looking to resize images whilst keeping the quality.
This is link one, without image resize
http://horble.com/test/test.php
This is linke two, with image resize.
http://horble.com/test/test1.php
As you can see, the resize image distorts the image, and for the image already displayed that isn't "No Photo" has a slight yellow tip on the nose and stuff. When that image gets bigger, the yellow patch gets bigger, when that image gets smaller, the yellow gets smaller.

I need to retain image quality. I do not use GD Graphics Library, although I DO have it installed. I've never used it, not sure how. Hope you can point me in the right way.

Here is the PHP coding for the script that calls the image.

<?php
$num_printed = 0;
$sql = mysql_query("SELECT Avatar FROM users WHERE Activated = '0' ORDER BY RAND() LIMIT 12");
if (mysql_num_rows($sql) > 0) {
  while ($item = mysql_fetch_array($sql)) {
	  echo '<a href="#"><img src="resize_image.php?file='.$item['Avatar'].'" alt="user" title="" border="0" /></a>';
      $num_printed += 1;
  }
}
while( $num_printed < 12 ) {
    echo '<img src="resize_image.php?file=profile/photos/default/default.jpg" alt="default" title="" border="0" />';
    $num_printed += 1;
}
?>

Here is the "resize_image.php" the page that resizes the images.

<?php 
	$pic = $_GET['file'];
	
	if (!isset($max_width))
      $max_width = 90;
   if (!isset($max_height))
      $max_height = 110;
	  	
	$size = GetImageSize($pic);
	$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($pic);
	$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);
	imagedestroy($src);
	imagedestroy($dst);
?>

Hope you can help me!

Edited by TeddyKiller: n/a

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by TeddyKiller
0

I've changed a few things. At the bottom of the code

$src = imagecreatefromjpeg($pic);
	$dst = imagecreatetruecolor($tn_width, $tn_height);
	imagecopyresampled($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width,$height);
	
	header('Content-type: image/jpeg');
	imagejpeg($dst,NULL,100);
	imagedestroy($src);
	imagedestroy($dst);

Now what I'm in need of doing, is the cropping.
if lets say the image is well out of proportion. eg: 100 x 720 so that it is a rectangle to crop it to a squarer shape, though I can't do that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.