1

I have a file field and I upload a file using PHP.

I need to re-size the image but I should get minimum height and width, which means no matter what is the size of the original image, if I re size the image the height should be greater than 180px and width should be greater than 160px. so how can I get resized image (thumbnail) with minimum height and width ?

I tried

$minImageWidth = 160;
$minImageHeight = 180;


$curWidth  = 850;
$curHeight = 900;

if ($curWidth>$minImageWidth && $curHeight>$minImageHeight) 
{
   $ratio = $curWidth/$curHeight;
    $zoom = $ratio > 1
         ? $minImageHeight / $curHeight
         : $minImageWidth / $curWidth
         ;

    echo $newWidth = $curWidth * $zoom;
  echo '<br>';
    echo $newHeight = $curHeight * $zoom;
}

but it doesnt work always (for example 300X300 gives wrong data output)

Joel
  • 49
  • 7
  • It's working just fine for me. I put in 300x300 and it returned 160x160. 850x900 also gave the right size. I think you're good to go. Unless you can give us a value that doesn't work. Note: I would made this a comment not an answer if I had the reputation level to comment – user2874270 Feb 25 '14 at 07:20
  • yes it gives 160X160 but I need minimum height 180 not 160 – Joel Feb 25 '14 at 07:22
  • also 850X900 gives 160X169, this is also wrong. height should be > 180 – Joel Feb 25 '14 at 07:23
  • You know I just realized that your code doesn't do what your question is asking. You said you need a minimum height of 180. In other words it has to be at least 180 pixels tall. 300x300 is bigger, so it should leave it alone. Your code is setting the maximum size, not minimum. – user2874270 Feb 25 '14 at 07:23
  • yes, u r correct. something wrong on the code, and I am looking for someone to help me, thanks – Joel Feb 25 '14 at 07:25
  • nobody here to help me out ? – Joel Feb 25 '14 at 07:45
  • I don't think anyone is helping because you haven't accurately explained what you want. I'm going to take a wild guess. You want it to be as small as possible without being smaller than 160 wide or 180 tall. That's not what you said you wanted, but it makes sense knowing that you're making a thumbnail. `code` – user2874270 Feb 25 '14 at 20:13

0 Answers0