Resize image after upload

2019-05-27 13:23发布

I want images to resize after upload in 4 different formats. If i resize it to best fit(i.e aspect ratio) some images come too small if height or width is too large than the other and if i resize it to fixed size then images get skewed. So what is the best way to resize a image. I am currently doing this using via imagemagik thumbnailImage() but i think it's a general problem. What are sites like google or facebook doing. what is the best thing to do in that case

2条回答
老娘就宠你
2楼-- · 2019-05-27 13:36

You can also use ImageWorkshop: http://phpimageworkshop.com/doc/17/resizing.html

$layer = new ImageWorkshop(array("fileObject" => $_FILES["uploadedImage"]));
$layer->resizeInPixel(200, 150, true); // Conserve proportion !
$layer->save(__DIR__."/web/uploads/2012", "thumb.png", true, null, 95);

You will have a resized picture of 200px/150px with conserved proportion !

查看更多
3楼-- · 2019-05-27 13:47

You can use resize functionality for resize image in different size during upload image. For example:

 include('SimpleImage.php');
  $image = new SimpleImage();
  $image->load($_FILES['uploaded_image']['tmp_name']);
  $image->resizeToWidth(300);
  $image->resizeToHeight(200);
  $image->save('resizeImage.jpg'

Similarly, you can save image in different size.

For more in detail you can find here:

http://sanjeevkumarjha.com.np/how-to-resize-and-crop-image/

查看更多
登录 后发表回答