retina_image_tag 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # retina_image_tag
2
2
 
3
- A high-resolution image is loaded when the retina_image_tag is called from a retina display
3
+ retina_image_tag is a ViewHelper for Rails 3.1. in contrast to the normal Rails image_tag knows the retina_image_tag if the user invokes an image on a Apple Retina Display.
4
4
 
5
- more info about the problem: http://theindustry.cc/2012/03/30/2x-the-retina-dilemma/
5
+ ### Retina Display
6
+ The Retina Display on the iPhone4 and iPad3 doubles the pixel resolution of the display.
7
+ You can think about a full screen display with dimensions of 320x480 for iPhone4 and 1024x768 for iPad3. The big difference is that these dimensions are now expressed in points not in pixels. What has changed is the scaling factor of the screen which determines how a point relates to a pixel. The iPhone4 retina display has a scale of 2 so that 1 point = 2 pixels.
6
8
 
7
- exampleapp: http://retinaimagetag-demoapp.herokuapp.com/
9
+ ### @2x
10
+ The '@2x' naming convention will be instantly familiar to any iOS developer. It's simply a way of naming an alternate, high-resolution version of an image so that it will be recognized and used by high-resolution Retina Displays.
8
11
 
9
- exampleapp sourcecode: https://github.com/ffaerber/retina_image_tag_demoapp
12
+ ### Example
13
+ herokuapp: <http://retinaimagetag-demoapp.herokuapp.com/>
14
+
15
+ sourcecode: <https://github.com/ffaerber/retina_image_tag_demoapp/>
10
16
 
11
17
 
12
18
 
@@ -18,7 +24,7 @@ Add this line to your application's Gemfile:
18
24
 
19
25
  add this line to application.js:
20
26
 
21
- $ //= require retina_image_tag
27
+ //= require retina_image_tag
22
28
 
23
29
  And then execute:
24
30
 
@@ -29,14 +35,28 @@ And then execute:
29
35
 
30
36
  ## Usage
31
37
 
32
- create a normal image: foo.jpg (400x400px)
38
+ ```erb
39
+ <%= retina_image_tag 'foo.jpg', :size => "400x400" %>
40
+ ```
41
+
33
42
 
34
- and a @2x Retina Images: foo@2x.jpg (800x800px)
43
+ ## Workflow
35
44
 
36
- and use it like normal
45
+ start working with the @2x version.
37
46
 
38
- <%= retina_image_tag 'foo.jpg', :size => "400x400" %>
47
+ To scale down the @2x images run `rake retina_image_tag:convert`, the rake task will look for @2x image in `app/assets/images/`, creates a copy and renames those files and reduces the image dimensions.
48
+
49
+ before:
50
+
51
+ * `foo@2x.jpg (800x800px)`
52
+ * `subdir/bar@2x.png (1000×556px)`
53
+
54
+ after:
39
55
 
56
+ * `foo@2x.jpg (800x800px)`
57
+ * `foo.jpg (400x400px)`
58
+ * `subdir/bar@2x.png (1000×556px)`
59
+ * `subdir/bar.png (500×278px)`
40
60
 
41
61
 
42
62
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module RetinaImageTag
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'fastimage'
2
+
1
3
  module RetinaImageTag
2
4
  module ViewHelpers
3
5
 
@@ -7,18 +9,32 @@ module RetinaImageTag
7
9
  end
8
10
 
9
11
 
12
+ def full_image_path
13
+ if Rails.env == 'development'
14
+ Rails.root.to_s+'/app/assets/images/'+@image
15
+ else
16
+ request.protocol + request.host_with_port + image_path(@image)
17
+ end
18
+ end
19
+
20
+
10
21
  def retina_image_tag(image, options = {})
11
22
  @devicePixelRatio = cookies[:devicePixelRatio]
12
23
  @options = options
13
24
  @image = image # foo.jpg, subdir/foo.png
14
25
 
26
+
27
+ if @options[:size] == nil
28
+ @options[:size] = FastImage.size(full_image_path.delete '@2x').join("x")
29
+ end
30
+
15
31
  case @devicePixelRatio
16
32
  when '2'
17
33
  retina_image 2
18
34
  when '1.5'
19
35
  retina_image 2
20
36
  else
21
- image_tag(@image, @options)
37
+ image_tag(@image, @options)
22
38
  end
23
39
  end
24
40
 
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "railties", "~> 3.1"
19
19
  gem.add_dependency "rmagick", "~> 2.13.1"
20
-
20
+ gem.add_dependency "fastimage", "~> 1.2.13"
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retina_image_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 2.13.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: fastimage
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.13
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.13
46
62
  description: ! 'A high-resolution image is loaded when the retina_image_tag is called
47
63
  from a retina display '
48
64
  email: