Code Monkey home page Code Monkey logo

smartclip's Introduction

Smartclip

Smartclip is a contextually-aware paperclip processor that crops and scales your images to maximize aesthetic quality.

While initially written as a passion project for The Glass Files, I've abstracted away all the hardcoded specifics so it should work generically. Images smaller than the desired thumbnail size are automatically padded with a border rather than being enlarged.

The Algorithm

The algorithm is fairly simple and is an adjusted a port of smartcrop.js by Jonas Wagner:

  • Find edges
  • Find regions with a color like skin
  • Find regions high in saturation
  • Generate a set of thumbnail candidates
  • Rank candidates using an importance function to focus the detail in the center and avoid it in the edges.
  • The highest ranking candidate is selected and is processed by Paperclip

Example

The process is super simple, and is basically identical to using any other Paperclip processor:

  # Your path might be different, so adjust as necessary
  require "#{Rails.root}/lib/paperclip_processors/smartclip"
  
  ...

  styles: { thumb: { resize_width: 150, resize_height: 150, processors: [:smartclip] } }

Future Plans

  • Wrap within gem for easy installation
  • Optimize pixel iteration to reduce number of loops. Can it be done without screwing with saliency patterns?
  • Port and integrate face detection algorithm
  • Completely rewrite to favor deep neural networks? Benefits from more complicated criteria, and can be trained from professional data rather than guesses
  • Extract optimzation logic, along with what I've learned, to create separate image optmization processor?

Found Bugs?

If you found a bug, submit an issue. If you have some optimization insight, submit a Pull Request.

smartclip's People

Contributors

thearchitector avatar

Watchers

 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.