How to resize an image?

I’m creating an image upload. I use S3, Slingshot, Cropper and aws-sdk. How do I resize an image?

1 Like

Probably 3 options for now:

  1. Create a lambda service that resizes an image on s3 upload: https://aws.amazon.com/lambda/details/
  2. Use something like imagemagick: https://atmospherejs.com/classcraft/imagemagick
  3. Use a client-side resizing package like: https://atmospherejs.com/thinksoftware/image-resize-client

Thanks. Looks like the best choice. Imagemagick requires a tour pass my server so no point when using Slingshot. The other package doesn’t work in iOS8, otherwise that would be good.

Btw, doesn’t iOS and Android have this functionally, resizing, built in or can’t meteor access that?

Any Lambda tutorial for a simple resize script? :smile:

http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-create-function.html :wink:

It’s just node running with graphicsmagick, all quite simple to figure out.

1 Like

Very helpful as AWS is a bit overwhelming with all the info and solutions. Hopefully I’ll will solve it from there.

I know you cannot hit lambda directly from the client(without exposing secret key), so can you get the upload request to s3 callback to return only after the resize is complete? Or it will return as soon as the initial upload is complete?

It will return after the upload, lambda runs completely separate from s3. What’s your use case that you’d want to know when lambda is finished? If it’s for showing the image I’d suggest you show the non-resized version on upload and resized afterwards.

perhaps not helping your current setup, but I prefer resize-on-the-fly methods like the one filepicker suggests: https://www.filepicker.com/documentation/file-processing/image-conversion/image

Imagine you are changing your cover photo for your profile page i want to show cropped/resized version right away so the user can look at what it really looks like. But i am guessing there is no speed concern with lamdba right? because you can run infinite many of them in parallel?

Indeed, if the source image isn’t overly large the latency is negligible.

I really like this answer.

Damn i have the highest ram setting on lambda, and it’s taking around 10-18 seconds to resize a 4MB image into 5 sizes (with width: 2000, 1800, 1000, 240, 70), locally it’s taking around 3-4 seconds. Idk if i should use EC2 instead.

edit: jk now it’s taking around 3 seconds, thats awesome!

1 Like

You could split the different sizes up in different lambda processes, that way they are executed in parallel, other than that I have no immediate tip to improve the processing time.

I’ve recommended and used Cloudinary.com for clients in the past.

Well worth the money.

Im about to set up Google Cloud for myself. I like how you just request the image size you want in the url which is really handy for prototyping.