bcms_thumbnail 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -10,11 +10,11 @@ This extension adds a "thumbnail" view helper that takes a content_block with an
10
10
 
11
11
  == Examples
12
12
 
13
- It's pretty simple. The code below demonstrates creating a thumbnail from an image block, which (naturally) has a browser_cms attachment. This code overrides the default 100x100 geometry and creates images of no larger than 125 pixels on any side.
13
+ It's pretty simple. The code below demonstrates creating a thumbnail from an image block, which (naturally) has a browser_cms attachment. This code overrides the default 100x100 geometry and creates images of no larger than 125 pixels on any side, with a quality of 85.
14
14
 
15
15
  Add a dynamic portlet and the add this to the template:
16
16
  <% image = ImageBlock.find(:first) %>
17
- <%= image_tag(thumbnail(image,'125x125')) %>
17
+ <%= image_tag(thumbnail(image,'125x125',85)) %>
18
18
 
19
19
  A stupidly simple image gallery? It's easier than you think! Again, in a dynamic portlet:
20
20
 
@@ -38,6 +38,12 @@ You can also create square thumbnails via the "thumbnail_square" helper. You sho
38
38
  <% image = ImageBlock.find(:first) %>
39
39
  <%= image_tag(thumbnail_square(image,'125')) %>
40
40
 
41
+ So "thumbnail" and "thumbnail_square" accept three parameters:
42
+
43
+ # The object with the attachment,
44
+ # The geometry, and
45
+ # An integer representing the JPG compression level, from 1 to 100. Default is 85.
46
+
41
47
  == Geometries
42
48
 
43
49
  ImageMagick will preserve aspect ratio with all the geometries below:
@@ -4,21 +4,21 @@ module ActionView
4
4
  module Helpers
5
5
  module_function
6
6
 
7
- def thumbnail(attachment_obj,geometry = '100x100')
8
- thumbnail_engine(attachment_obj,geometry,false)
7
+ def thumbnail(attachment_obj,geometry = '100x100', quality = 85)
8
+ thumbnail_engine(attachment_obj, geometry, false, quality)
9
9
  end
10
10
 
11
- def thumbnail_square(attachment_obj,geometry = '100')
11
+ def thumbnail_square(attachment_obj,geometry = '100', quality = 85)
12
12
  fixed_geometry = geometry
13
13
  if geometry.match(/\D/)
14
14
  fixed_geometry = geometry.split(/\D/)[0]
15
15
  end
16
- thumbnail_engine(attachment_obj,geometry,true)
16
+ thumbnail_engine(attachment_obj, geometry, true, quality)
17
17
  end
18
18
 
19
- def thumbnail_engine(attachment_obj,geometry = '100x100',square = false)
19
+ def thumbnail_engine(attachment_obj,geometry = '100x100',square = false, quality = 85)
20
20
  if ! attachment_obj.blank? && attachment_obj.respond_to?('attachment') && ['jpg','png','gif','bmp'].include?(attachment_obj.attachment.file_extension.downcase)
21
- thumbnail_location = "/bcms_thumbnail_cache/#{geometry}/#{attachment_obj.attachment.file_location.gsub(/[\\\/]/,'-')}#{(square) ? '-square' : ''}.jpg"
21
+ thumbnail_location = "/bcms_thumbnail_cache/#{geometry}/#{attachment_obj.attachment.file_location.gsub(/[\\\/]/,'-')}#{(square) ? '-square' : ''}#{quality}.jpg"
22
22
  if ! File.exists?("#{RAILS_ROOT}/public#{thumbnail_location}")
23
23
  if ! File.exists?("#{RAILS_ROOT}/public/bcms_thumbnail_cache/#{geometry}")
24
24
  FileUtils.mkdir_p("#{RAILS_ROOT}/public/bcms_thumbnail_cache/#{geometry}")
@@ -26,6 +26,7 @@ module ActionView
26
26
  FileUtils.chmod 0755, "#{RAILS_ROOT}/public/bcms_thumbnail_cache/#{geometry}"
27
27
  end
28
28
  image = MiniMagick::Image.from_file("#{RAILS_ROOT}/tmp/uploads/#{attachment_obj.attachment.file_location}")
29
+ image.quality quality
29
30
  if square
30
31
  if image[:width] < image[:height]
31
32
  remove = ((image[:height] - image[:width])/2).round
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 4
9
- version: 1.0.4
8
+ - 5
9
+ version: 1.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Collis-Puro