Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
Bear with me: markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
peleteiro committed Apr 22, 2011
1 parent 86fdf41 commit 9b34126
Showing 1 changed file with 25 additions and 58 deletions.
83 changes: 25 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,93 +25,69 @@ Using

Mugshot provides you with a Sinatra application. You can create a **config.ru** file with these contents to start using Mugshot:

<pre>
# -*- encoding: utf-8 -*-
require "rubygems"
require "mugshot"

run Mugshot::Application.new(:storage => Mugshot::FSStorage.new("/tmp/mugshot"))
</pre>

Using activeresource (3.0.6)
Then you can run it with:

<pre>
$ rackup config.ru
</pre>
$ rackup config.ru

And access in your browser:

<pre>
http://localhost:9292/myimg/some-name.jpg
</pre>
http://localhost:9292/myimg/some-name.jpg

This would simply return the image located at /tmp/mugshot/myimg, converting it to a JPEG. Additionaly you can pass some operations to be performed over the image:

<pre>
http://localhost:9292/resize/100x100/myimg/some-name.jpg # resizing to 100x100 pixels
http://localhost:9292/resize/100x/myimg/some-name.jpg # resizing to 100 pixels in width maintaining aspect ratio
http://localhost:9292/resize/x100/myimg/some-name.jpg # resizing to 100 pixels in height maintaining aspect ratio
http://localhost:9292/crop/200x150/myimg/some-name.jpg # resize and crop image to 200x150
http://localhost:9292/quality/70/crop/200x150/myimg/some-name.jpg # convert it to JPEG with quality of 70% and resize and crop image to 200x150
http://localhost:9292/background/red/crop/200x150/myimg/some-name.jpg # convert it to JPEG with red background and resize and crop image to 200x150
</pre>

Supported operations
--------------------

### Resize

<pre>
/resize/WIDTHxHEIGHT/id/name.jpg (ex: http://mugshot.ws/resize/200x100/myid/thumb.jpg)
</pre>
/resize/WIDTHxHEIGHT/id/name.jpg (ex: http://mugshot.ws/resize/200x100/myid/thumb.jpg)

### Resize keeping aspect ratio

<pre>
/resize/WIDTHx/id/name.jpg (ex: http://mugshot.ws/resize/200x/myid/thumb.jpg)
/resize/WIDTHx/id/name.jpg (ex: http://mugshot.ws/resize/200x/myid/thumb.jpg)

/resize/xHEIGHT/id/name.jpg (ex: http://mugshot.ws/resize/x100/myid/thumb.jpg)
</pre>
/resize/xHEIGHT/id/name.jpg (ex: http://mugshot.ws/resize/x100/myid/thumb.jpg)

### Crop

<pre>
/crop/WIDTHxHEIGHT/id/name.jpg (ex: http://mugshot.ws/crop/200x100/myid/thumb.jpg)
</pre>
/crop/WIDTHxHEIGHT/id/name.jpg (ex: http://mugshot.ws/crop/200x100/myid/thumb.jpg)

### Quality

<pre>
/quality/QUALITY/id/name.jpg (ex: http://mugshot.ws/quality/70/myid/thumb.jpg)
</pre>
/quality/QUALITY/id/name.jpg (ex: http://mugshot.ws/quality/70/myid/thumb.jpg)

### Background

<pre>
/background/COLOR/id/name.jpg (ex: http://mugshot.ws/background/red/myid/thumb.jpg)
</pre>
/background/COLOR/id/name.jpg (ex: http://mugshot.ws/background/red/myid/thumb.jpg)


Configuration
-------------

You can further configure your Mugshot::Application when creating it, like so:

<pre>
# -*- encoding: utf-8 -*-
require "rubygems"
require "mugshot"

run Mugshot::Application.new(
:storage => Mugshot::FSStorage.new("/tmp/mugshot"),
:cache_duration => 7.days.to_i, # duration set in cache header (in seconds)
:allowed_sizes => ['640x360', '480x360', '320x240'], # an array with valid sizes for resize and crop operations
:allowed_formats => [:jpg, :png], # an array with the allowed formats
:allowed_names => ['thumb', 'img'], # an array with the allowed names in the URL
:quality_range => 1..100, # the range of allowed values for quality operations
:valid_operations => [:crop, :resize, :quality] # an array with the valid operations
)
</pre>
# -*- encoding: utf-8 -*-
require "rubygems"
require "mugshot"

run Mugshot::Application.new(
:storage => Mugshot::FSStorage.new("/tmp/mugshot"),
:cache_duration => 7.days.to_i, # duration set in cache header (in seconds)
:allowed_sizes => ['640x360', '480x360', '320x240'], # an array with valid sizes for resize and crop operations
:allowed_formats => [:jpg, :png], # an array with the allowed formats
:allowed_names => ['thumb', 'img'], # an array with the allowed names in the URL
:quality_range => 1..100, # the range of allowed values for quality operations
:valid_operations => [:crop, :resize, :quality] # an array with the valid operations
)

When using the restrictive configurations any value other than the ones allowed will result in a 400 status code being returned. If no restriction is set then any value can be given, which can lead to DOS attacks. Be careful!

Expand All @@ -120,19 +96,10 @@ Development

Clone the repository and run:

<pre>
$ bundle install
</pre>
$ bundle

This will install all dependencies for you. Then you can run the specs and features:

<pre>
$ rake spec
$ rake cucumber
</pre>


Who's using
-----------
$ rake spec
$ rake cucumber

We currently use Mugshot with Varnish on [Baixatudo](http://www.baixatudo.com.br).

0 comments on commit 9b34126

Please sign in to comment.