如果图像超过高度/宽度,用载波调整图像的大小

时间:2023-01-19 20:30:31

I have looked around and could not find a solution after I tried to do it on my own. When users upload photos, I want for them to be resized if it exceeds my minimum and max dimensions. However I would like two conditionals. The photos that were taken sideways (East/West) should remain within the dimensions I set, and the same follows for the photos taken the tall way (North/South).

我四处看了看,没能找到解决的办法,我自己试着去做。当用户上传照片时,如果照片超过了我的最小和最大尺寸,我想让他们调整尺寸。但是我想要两个条件。侧向拍摄的照片(东/西)应该保持在我设置的尺寸范围内,而高架拍摄的照片(北/南)也应该保持同样的尺寸。

For example is a user uploads a photo that's standing the long way and has dimensions of 3264x1840. The upload should be resized to fit 584x329. If the upload is less than 584x329 then it will not adjust the size.

例如,用户上传一张照片,它站在很远的地方,尺寸为3264x1840。上传的大小应该调整到适合584x329。如果上载小于584x329,则不会调整大小。

The other example is if user uploads a photo that was taken the tall way and it had dimensions of 2448 x 3264. The upload should be resized to fit 247x329.

另一个例子是,如果用户上传了一张照片,照片的尺寸是2448x3264。上传的大小应该调整为247x329。

I was trying to use MiniMagick with this as I believe that would be the requirement. If I can only use CarrierWave then that's perfect, but I thought MiniMagick was supposed to be used for resizing photos.

我试着用MiniMagick来做这个,因为我相信这是必须的。如果我只能使用CarrierWave,那就太完美了,但是我认为MiniMagick被用来调整照片的大小。

The error I receive is 'undefined method resize' for #<ImageUploader:0x007f8606feb9b8>' and it points to@photo = Photo.new(params[:photo])` from def create in the controller.

我收到的错误是# <0x007f8606feb9b8>

<>>>

><


  

>

>


  

>

>