Jump to content

PHP Image crop with GD help


EagerWolf

Recommended Posts

Here is my code which should do resize:


		$wm = $newwidth/$framed_img_w;  // Izracunamo razmerje med trenutno novo dolzino slike in zahtevano dolzino slike
		$hm = $newheight/$framed_img_h; // Izracunamo razmerje med trenutno novo visino slike in zahtevano visino slike
		$h_height = $framed_img_h/2;    // Podamo polovico zahtevane velikosti slike
		$w_height = $framed_img_w/2;	// Podamo polovico zahtevane dolzine slike

		if($newwidth > $newheight) // V primeru, ko je slika podolgovata
		{
			$adjusted_width = $newwidth / $hm;
			$half_width = $adjusted_width / 2;
			$int_width = $half_width - $w_height;
			imagecopyresampled($croped,$resized_img,-$int_width,0,0,0,$adjusted_width,$framed_img_h,$newwidth,$newheight);
		} 

		elseif(($newwidth < $newheight) || ($newwidth == $newheight)) // V primeru, ko je slika pokoncna ali kvadratna
		{
			$adjusted_height = $newheight / $wm;
			$half_height = $adjusted_height / 2;
			$int_height = $half_height - $h_height;
			imagecopyresampled($croped,$resized_img,0,-$int_height,0,0,$framed_img_w,$adjusted_height,$newwidth,$newheight);
		} 

 

$newwidth & $newheight are given by a script above, which resizes image to 300, newheight, or newwidth, 300 pixels.

 

My script works for for images when width > height...

 

When you add image where height > width, image is just resized to 300, 300 pixels...

 

Please help!

Link to comment
https://forums.phpfreaks.com/topic/38475-php-image-crop-with-gd-help/
Share on other sites

Check out thumb.php at http://stephen.calvarybucyrus.org/code/5

 

Set these two variables (they should be the same)

$th_max_width = 250;  // Maximum width of the thumbnail
$th_max_height = 250; // Maximum height of the thumbnail

 

and call like this:

<?php
echo "<IMG src=\"thumb.php?file=".$filename."\">";
?>

$filename must be a relative path for the full-size picture.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.