Code Monkey home page Code Monkey logo

image-uploads's Introduction

A solution to uploading photos with AWS Lambda

Why?

Helping people communicate in pictures makes their lives better.

What?

A simple image uploader module that can be included within your project.

It will:

  • Upload imagess (to S3 and Google drive/photos) effortlessly
  • Use ImageMagic to automatically re-size & optimise the image for mobile devices
  • Return a list of the images that were uploaded to S3 for use in other objects.

Image Re-Sizing using gm

gm depends on ImageMagick. On a Mac you will need Homebrew to install ImageMagic (the easy & fast way.)

brew install imagemagick

If you want to enable WebP support for your images, you must include the following flag in your installation command:

brew install imagemagick --with-webp

Usage: https://www.npmjs.com/package/gm

Image Rotation

We started using this code in staging today and users started uploading images imediately.

"Its faster than Instagram!" ~ A User

Was a user comment that delighted us.

However they uploaded images from their iDevices which were not in the correct orientation...

So we need to add rotation.

Assumptions

Aproximately 90% of people are right-handed.

iphone landscape right-handed

Therefore we need to rotate images 90 degrees clockwise.

We'll be using gm for our image rotation.

Understanding JPEG Exif Orientation

For convenience, here is what the letter F would look like if it were tagged correctly and displayed by a program that ignores the orientation tag (thus showing the stored image):

  1          2         3        4         5                 6           7            8

888888    888888        88    88        8888888888    88                   88   8888888888
88            88        88    88        88  88        88  88           88  88       88  88
8888        8888      8888    8888      88            8888888888   8888888888           88
88            88        88    88
88            88    888888    888888

Temporary Folder / Files

Usage: https://github.com/raszi/node-tmp
Latest version: https://www.npmjs.org/package/tmp

Research (way more detail than you'll ever need)

Image-upload-as-a-Service Provider

How are others solving the problem?

There was a suggestion to use Meteor CollectionFS: https://github.com/CollectionFS/Meteor-CollectionFS to upload/store images. This is a terrible idea because the file gets stored in MongoDB! Not only is MongoDB storage considerably more expensive, its also slower than a CDN!! (If you know why this is a good idea, please tell me!)

Avoid Filename Collisions with Hashes

All the big players are storing files with generated names (instead of using the files' original name such as "photo1.jpg" thus avoiding name collisions) e.g:

Google is maintaining the file name and storing it in a folder:

Should we maintain the filename? I tend to re-name all the photos I want to be able find later. So does giving these hash.jpg on our system loose some valuable information...? (feedback please...!)

Helpful Links

Troubleshooting

History

I've partially "solved" this problem before:

I need to re-visit these and get them working together (with tests :-)

Popular Image Web/Mobile Sites/Apps

The more successful image apps on the web/mobile:

image-uploads's People

Contributors

jackcarlisle avatar nkamc avatar nelsonic avatar cleop avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.