Created
May 3, 2012 13:43
-
-
Save peterhellberg/2585739 to your computer and use it in GitHub Desktop.
Check image dimensions using the Dimensions gem.
This file contains hidden or 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
require 'json' | |
class ImageDimensions < Sinatra::Base | |
get "/" do | |
'API: GET /[ur_product_id].json' | |
end | |
get /(\d{6})\.json/ do |ur_product_id| | |
content_type :json | |
data = { exists: false } | |
['jpg', 'png'].each do |e| | |
p = path(ur_product_id, e) | |
data = { | |
exists: true, ext: e, url: url(p), | |
width: Dimensions.width(p), | |
height: Dimensions.height(p) | |
} if File.exists? p | |
end | |
JSON.dump(data) | |
end | |
def root_path | |
"/var/www/apps/ur-image-manager/shared/system/data" | |
end | |
def path(ur_product_id, ext = 'jpg') | |
"#{root_path}/#{ur_product_id}/original/1.#{ext}" | |
end | |
def url(path) | |
path.gsub "#{root_path}", 'http://bilduppladdning-data.ur.se' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment