2

I'm allowing user uploads, and I want to scale their images up if they're too small (low quality is a non-issue). I need to make the smallest side become 150px and have the other dimension scale up to keep the aspect ratio. I need to make it work for .jpg, .gif and .png files.

Any pointers would be greatly appreciated, I'm struggling to find anything about making images larger like this.

Danny
  • 165
  • 1
  • 12
  • possible duplicate of [dynamically scale images in php jpg/png/gif](http://stackoverflow.com/questions/1248149/dynamically-scale-images-in-php-jpg-png-gif) – ChrisF Aug 29 '10 at 17:03
  • PHP docs: http://www.php.net/manual/en/function.imagecopyresampled.php and http://www.php.net/manual/en/function.imagecopyresized.php Lots of examples there – Imre L Aug 29 '10 at 17:08

2 Answers2

3

As answered here, give it a try to WideImage.

Community
  • 1
  • 1
Alexander
  • 23,432
  • 11
  • 63
  • 73
1

Thanks to Alexander for the WideImage suggestion.

I simply used this:

require_once('WideImage/WideImage.php');
$image = WideImage::load($_FILES['image']['tmp_name']);
$resized = $image->resize(150,150,'outside','up');
$resized->saveToFile($target_file);

It worked perfectly, and by using the "up" option, it only scales images smaller than the dimensions set up, and leaves everything else.

Danny
  • 165
  • 1
  • 12