Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call strip on thumbnails to reduce their size #2261

Merged
merged 3 commits into from
Jun 5, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/app/helpers/refinery/image_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def image_fu(image, geometry = nil, options={})
if image.present?
dimensions = (image.thumbnail_dimensions(geometry) rescue {})

image_tag(image.thumbnail(geometry).url, {
image_tag(image.thumbnail(:geometry => geometry,
:strip => options[:strip]).url, {
:alt => image.respond_to?(:title) ? image.title : image.image_name,
}.merge(dimensions).merge(options))
end
Expand Down
4 changes: 2 additions & 2 deletions images/app/helpers/refinery/admin/images_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def other_image_views
def thumbnail_urls(image)
thumbnail_urls = {
:"data-original" => asset_paths.compute_public_path(image.url, ''),
:"data-grid" => asset_paths.compute_public_path(image.thumbnail('135x135#c').url, '')
:"data-grid" => asset_paths.compute_public_path(image.thumbnail(:geometry => '135x135#c').url, '')
}

Refinery::Images.user_image_sizes.sort_by{|key,geometry| geometry}.each do |size, pixels|
thumbnail_urls[:"data-#{size.to_s.parameterize}"] = asset_paths.compute_public_path(image.thumbnail(pixels).url, '')
thumbnail_urls[:"data-#{size.to_s.parameterize}"] = asset_paths.compute_public_path(image.thumbnail(:geometry => pixels).url, '')
end

thumbnail_urls
Expand Down
31 changes: 22 additions & 9 deletions images/app/models/refinery/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ def per_page(dialog = false, has_size_options = false)
end
end

# Get a thumbnail job object given a geometry.
def thumbnail(geometry = nil)
if geometry.is_a?(Symbol) && Refinery::Images.user_image_sizes.keys.include?(geometry)
geometry = Refinery::Images.user_image_sizes[geometry]
# Get a thumbnail job object given a geometry and whether to strip image profiles and comments.
def thumbnail(options = {})
if options.is_a?(String) || options.is_a?(Symbol)
Refinery.deprecate 'Refinery::Image#thumbnail(geometry)',
:replacement => 'Refinery::Image#url(:geometry => value)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add :when here and set it to 2.2? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also shouldn't Refinery::Image#url be Refinery::Image#thumbnail instead?

options = { :geometry => options }
end

if geometry.present? && !geometry.is_a?(Symbol)
image.thumb(geometry)
else
image
end
options = { :geometry => :no_geometry, :strip => true }.merge(options)
geometry = convert_to_geometry(options[:geometry])
thumbnail = image
thumbnail = thumbnail.thumb(geometry) unless geometry.is_a?(Symbol)
thumbnail = thumbnail.strip if options[:strip]
thumbnail
end

# Intelligently works out dimensions for a thumbnail of this image based on the Dragonfly geometry string.
Expand Down Expand Up @@ -101,5 +104,15 @@ def title
CGI::unescape(image_name.to_s).gsub(/\.\w+$/, '').titleize
end

private

def convert_to_geometry(geometry)
if geometry.is_a?(Symbol) && Refinery::Images.user_image_sizes.keys.include?(geometry)
Refinery::Images.user_image_sizes[geometry]
else
geometry
end
end

end
end
6 changes: 3 additions & 3 deletions images/spec/models/refinery/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ module Refinery
end

it "becomes different when supplying geometry" do
created_image.url.should_not == created_image.thumbnail('200x200').url
created_image.url.should_not == created_image.thumbnail(:geometry => '200x200').url
end

it "has different urls for each geometry string" do
created_image.thumbnail('200x200').url.should_not == created_image.thumbnail('200x201').url
created_image.thumbnail(:geometry => '200x200').url.should_not == created_image.thumbnail(:geometry => '200x201').url
end

it "uses right geometry when given a thumbnail name" do
name, geometry = Refinery::Images.user_image_sizes.first
created_image.thumbnail(name).url.should == created_image.thumbnail(geometry).url
created_image.thumbnail(:geometry => name).url.should == created_image.thumbnail(:geometry => geometry).url
end
end

Expand Down