Skip to content

Commit

Permalink
fixes for image height and width
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi committed Jun 11, 2009
1 parent cf86170 commit 500705c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 12 additions & 1 deletion app/models/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,19 @@ def extension

def dimensions(size='original')
@dimensions ||= {}
# ext = self.extension

# image_file = self.asset.path

# if size != 'original'
# if !self.asset.styles[size.to_sym][:format].nil?
# ext = self.asset.styles[size.to_sym][:format]
# end
# image_file = self.asset.path(size).gsub(/\.+#{self.extension}/, ".#{ext}")
# end

@dimensions[size] ||= image? && begin
image_file = self.path(size)
image_file = "#{RAILS_ROOT}/public#{self.thumbnail(size)}"
image_size = ImageSize.new(open(image_file).read)
[image_size.get_width, image_size.get_height]
rescue
Expand Down
11 changes: 6 additions & 5 deletions app/models/asset_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ class TagError < StandardError; end
if asset.image?
size = options['size'] ? options.delete('size') : 'icon'
container = options.delete('container')
root = "#{RAILS_ROOT}/public#{asset.thumbnail(size)}"
img_height = 0
open(root, "rb") do |fh|
img_height = ImageSize.new(fh.read).get_height
end
# root = "#{RAILS_ROOT}/public#{asset.thumbnail(size)}"
# img_height = 0
# open(root, "rb") do |fh|
# img_height = ImageSize.new(fh.read).get_height
# end
img_height = asset.height(size)
(container.to_i - img_height.to_i)/2
else
raise TagError, "Asset is not an image"
Expand Down

0 comments on commit 500705c

Please sign in to comment.