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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.