Coder Social home page Coder Social logo

ruby-thumbor's Introduction

ruby-thumbor

Github Actions - tests Github Actions - rubocop Gem Version Coverage Status

ruby-thumbor is the Ruby client to the thumbor imaging service (http://github.com/thumbor/thumbor).

Features

  • Generate thumbor encrypted URLs
  • Obtain metadata from image operations in thumbor

Install

gem install ruby-thumbor

Using it

require 'ruby-thumbor'

image = Thumbor::Cascade.new('my-security-key', 'remote-image.com/path/to/image.jpg')
image.width(300).height(200).watermark_filter('http://remote-image.com/path/to/image.jpg', 30).generate

# url will contain something like:
# /2913921in321n3k2nj32hjhj3h22/remote-image.com/path/to/image.jpg

# Now you just need to concatenate this generated path, with your thumbor server url

or

require 'ruby-thumbor'

crypto = Thumbor::CryptoURL.new 'my-security-key'

url = crypto.generate(width: 200, height: 300, image: 'remote-image.com/path/to/image.jpg')

Available Thumbor arguments

meta: bool # flag that indicates that thumbor should return only meta-data on the operations it would otherwise perform;

crop: [<int>, <int>, <int>, <int>] # Coordinates for manual cropping. The first item is the two arguments are the coordinates for the left, top point and the last two are the coordinates for the right, bottom point (thus forming the square to crop);

width: <int> # the width for the thumbnail;

height: <int> # the height for the thumbnail;

flip: <bool> # flag that indicates that thumbor should flip horizontally (on the vertical axis) the image;

flop: <bool> # flag that indicates that thumbor should flip vertically (on the horizontal axis) the image;

halign: :left, :center or :right # horizontal alignment that thumbor should use for cropping;

valign: :top, :middle or :bottom # horizontal alignment that thumbor should use for cropping;

smart: <bool> # flag that indicates that thumbor should use smart cropping;

filters: ['blur(20)', 'watermark(http://my.site.com/img.png,-10,-10,50)'] # array of filters and their arguments

If you need more info on what each option does, check thumbor's documentation at https://thumbor.readthedocs.io/en/latest/index.html.

Uploading to Rubygems

To upload a new version to Rubygems, simply update the version on the file lib/thumbor/version.rb then use the commit message Bump to <new version>, this will trigger the release process on Github actions.

License

(The MIT License)

Copyright (c) 2022 Bernardo Heynemann [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ruby-thumbor's People

Contributors

cezarsa avatar dlackty avatar emptyflask avatar fluke avatar gsouza-newstore avatar guilhermef avatar heynemann avatar jordan-thoms avatar okor avatar rafaelcaricio avatar robolson avatar runa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-thumbor's Issues

remove unused file

Very simple fix and no big deal.

Looks like the https://github.com/heynemann/ruby-thumbor/blob/master/install-python.sh file is not used and can be removed since this commit:

14235b7

Upgrade to Thumbor 3 secure url style

In case anybody may need this or can upgrade this gem to use Thumbor3 secure urls style.

Currently I use the following quick helper (build from standard gems only):

url = 'https://xxxx.cloudfront.net/200x200/images/12345.jpg'

def thumbor_secure_url(url)
  uri = URI.parse(url)
  hmac = OpenSSL::HMAC.digest("sha1", SECURITY_KEY, uri.path[1..-1])
  signature = Base64.encode64(hmac).tr("+", "-").tr("/", "_").chomp
  "#{uri.scheme}://#{uri.host}/#{signature}#{uri.path}"
end

Also JS version inspired original: https://github.com/dcaramelo/ThumborUrlBuilder/blob/master/index.js#L258-L278

Spec "should allow thumbor to decrypt it properly with filters" is failing

I am attempting to run the ruby-thumbor specs on my local machine and they are all passing except for one. I have Thumbor 3.5.2 installed and am testing with Ruby 1.9.3.

1) Thumbor::CryptoURL#generate :old => true should allow thumbor to decrypt it properly with filters
   Failure/Error: decrypted["filters"].should == "quality(20):brightness(10)"
     expected: "quality(20):brightness(10)"
          got: "" (using ==)
   # ./spec/ruby-thumbor_spec.rb:433:in `block (2 levels) in <top (required)>'

The most recent travis-ci build for ruby-thumbor is green but it built with Thumbor 3.0.1. My current guess is that something changed between 3.0.1 and 3.5.2 that is causing this test to fail.

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.