Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update /info to give a JSON response
includes a boolean for if the image is animated (or likely to be)
- Loading branch information
Showing
12 changed files
with
124 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'json' | ||
|
||
# Returns a json object with the height, width attributes | ||
class ScaleDown::Info | ||
|
||
def initialize(relative_path) | ||
path = [ScaleDown.public_folder, relative_path].join("/") | ||
if File.exists?(path) | ||
GC.start | ||
@image_list = Magick::Image.read(path) | ||
@image = @image_list.first | ||
else | ||
@missing = true | ||
end | ||
end | ||
|
||
def missing? | ||
@missing == true | ||
end | ||
|
||
def hash | ||
{ | ||
height: @image.rows, | ||
width: @image.columns, | ||
# is this an animated GIF or other file | ||
animated: @image_list.size > 1 | ||
} | ||
end | ||
|
||
def to_json | ||
JSON hash | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ScaleDown | ||
VERSION = "0.7.3" | ||
VERSION = "0.8.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require File.expand_path(File.dirname(__FILE__))+'/../test_helper' | ||
|
||
class ScaleDown::Info::Test < Test::Unit::TestCase | ||
context "#new" do | ||
setup do | ||
ScaleDown.public_folder = File.join(File.expand_path(File.dirname(__FILE__)), "..") | ||
end | ||
|
||
should "be missing? a non-existant image" do | ||
assert ScaleDown::Info.new("files/notthere.jpg").missing? | ||
end | ||
|
||
should "generate json" do | ||
info = ScaleDown::Info.new("files/graphic.png") | ||
assert info.to_json | ||
end | ||
end | ||
|
||
context "properties" do | ||
should "have dimentions" do | ||
info = ScaleDown::Info.new("files/graphic.png") | ||
assert_equal 200, info.hash[:width] | ||
assert_equal 400, info.hash[:height] | ||
end | ||
|
||
should "set the animation flag for animated gifs" do | ||
info = ScaleDown::Info.new("files/graphic.png") | ||
assert_equal false, info.hash[:animated] | ||
|
||
info = ScaleDown::Info.new("files/animated.gif") | ||
assert_equal true, info.hash[:animated] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters