facebook_cover_resize 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5707f679f0c85e492939ab95c2b7d3b5b625b739
4
- data.tar.gz: 9d65c69774143a91190e3fe8e1c515f7f8fcf07c
3
+ metadata.gz: ae8b549158edc3e8266b43bc0bca3dd02623758b
4
+ data.tar.gz: 2a68f2c0b8a814e08d20a774e9597941b5d795b2
5
5
  SHA512:
6
- metadata.gz: 3ee4b5916e5cd6caa1f124351bae81964629b9a05a99416c212fe6875f1ec60bba369c46fb0ff9fd22ca8cdf9ecf3083c27c00a19bfd45761f2bb524de3911a9
7
- data.tar.gz: 9bba516e5e645d20bc629e09beb356530132d0455d2a8215a8a9656f013fd5da2941198a29275e08037b376ba77215c4f8d2958a1f9f98c24ae706ca948d4fd7
6
+ metadata.gz: 9b94ce8e7618abc4b4e9b4fbe5cf199cb4ea40b77cf5168f758a9c687e08ef9790ea8888e5c4beb5e2dd7d9ea7353a9bb7cf5255bb9ca3c41bb014dd7b1e6f92
7
+ data.tar.gz: 6122d32a491fb2ccc3cf907fd6e2711fe7fef13310248112d67348d01acc94afc0471a322ffba5528f58897c46fe104faf74b75f96e4e4ccfeedcd3f41238122
@@ -1,5 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
4
+ - jruby-19mode
5
+ - 2.0.0
6
+ - 2.2
7
+ - ruby-head
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: ruby-head
5
11
  before_install: gem install bundler -v 1.13.7
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
1
  # Facebook Cover Resize
2
2
 
3
- This Gem allows to display and resize Facebook events' cover image according to offset_x / offset_y
4
- given by Facebook. Using this Gem, you can display event cover image exactly like they are on Facebook,
5
- no more distortions, no more poor cropping.
3
+ [![Build Status](https://travis-ci.org/gbarillot/facebook_cover_resize.png)](https://travis-ci.org/gbarillot/facebook_cover_resize)
6
4
 
7
- To use this Gem, you have to grab 3 parameters from Facebook:
5
+ This Ruby Gem let you display and resize both Facebook events and accounts cover images according to offset_x / offset_y provided by Facebook Graph API. Using this Gem, you can display cover images exactly as they are on Facebook.
6
+
7
+ To use this Gem, you have to grab 3 parameters from Facebook API:
8
8
 
9
9
  * offset_x (positive integer)
10
10
  * offset_y (positive integer)
11
11
  * cover source (the URL of the image)
12
12
 
13
- WARNING: aside from these data provided by Facebook, you'll also need the dimensions of the image itself!
14
- I use the [Fastimage](https://github.com/sdsykes/fastimage) Gem for this
13
+ Aside from these data provided by Facebook, you'll also need the dimensions of the image itself.
14
+ Personally I use the [Fastimage](https://github.com/sdsykes/fastimage) Gem for this
15
15
  and it's working perfectly fine.
16
16
 
17
17
  ## Installation
18
18
 
19
- Add this line to your application's Gemfile:
19
+ Add this line to your Gemfile:
20
20
 
21
21
  ```ruby
22
22
  gem 'facebook_cover_resize'
@@ -32,30 +32,39 @@ Or install it yourself as:
32
32
 
33
33
  ## Usage
34
34
 
35
- This Gem contains an algorithm for image size computations, and a Rails view helper. Using the view helper
36
- is as simple as :
35
+ This Gem contains an algorithm for image size computations, and some Rails view helpers. Using the view helpers
36
+ to display and resize an event cover is as simple as:
37
37
 
38
38
  ```ruby
39
39
  - @event = Event.find(123)
40
+ # @event.cover: String (raw URL)
41
+ # @event.original: Array, containing 2 positive integers
42
+ # @event.offsets: Array, containing 2 integers
43
+
40
44
  = event_cover_tag source: @event.cover, original: @event.cover_size, offsets: @event.offsets, width: 500
41
45
  ```
42
46
 
43
- Note: Although this Gem handles resizing, you MUST consider the original Facebook width/height ratio,
44
- which is 1.91 (500/262). That's why you can only set the new width for your thumbnails,
45
- height is then automatically computed.
47
+ If you want to display an account cover:
48
+
49
+ ```ruby
50
+ - @account = Account.find(123)
51
+
52
+ = account_cover_tag source: @account.cover, original: @account.cover_size, offsets: @account.offsets, width: 500
53
+ ```
46
54
 
47
- Example: Let's say you need to display your thumbnails in a 250px wide container. You only have to
48
- call the Gem using this width, height being automatically set to 250 / 1.91 = 131px
55
+ *Note:* This Gem handles resizing, but you MUST respect the original Facebook width/height ratios,
56
+ which is 1.91 (500/262) for events, and 2.66 (829/312) for an account cover. That's why you only have to set the new width for your thumbnails, height being automatically computed.
49
57
 
50
- ### Life outside of Rails
58
+ ### Life outside of the Rails
51
59
 
52
- If you don't want to use Rails, you can however just use the plain Algorithm:
60
+ If you don't want to use Rails, you can however simply use the plain Algorithm:
53
61
 
54
62
  ```ruby
55
63
  FacebookCoverResize.compute(
56
64
  original: [original_width, original_height],
57
- offsets: [offst_x, offset_y],
65
+ offsets: [offset_x, offset_y],
58
66
  width: width_you_want_for_final_display_in_pixels
67
+ ratio: 1.91
59
68
  )
60
69
  ```
61
70
  This outputs an array containing 4 values :
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["guillaume barillot"]
10
10
  spec.email = ["gbarillot@gmail.com"]
11
11
 
12
- spec.summary = "Compute width/size and offsets x/y for Facebook events cover image"
13
- spec.description = "Compute width/size and offsets x/y for Facebook events cover image"
12
+ spec.summary = "Compute width/size and offsets x/y for Facebook cover images"
13
+ spec.description = "Compute width/size and offsets x/y for Facebook cover images"
14
14
  spec.homepage = "https://github.com/gbarillot/facebook_cover_resize"
15
15
  spec.license = "MIT"
16
16
 
@@ -4,7 +4,7 @@ require 'facebook_cover_resize/railtie' if defined?(Rails)
4
4
  module FacebookCoverResize
5
5
  def self.compute(args)
6
6
  ow = args[:width].to_f
7
- oh = (ow / 1.91)
7
+ oh = (ow / args[:ratio])
8
8
 
9
9
  if args[:original].any? && args[:offsets].any?
10
10
  nw = args[:original].first.to_f
@@ -59,7 +59,7 @@ module FacebookCoverResize
59
59
  offset_y = 0
60
60
  end
61
61
 
62
- # [top, left, width, height]
62
+ # [margin-top, margin-left, image width, image height]
63
63
  out = [
64
64
  offset_y.ceil,
65
65
  offset_x.ceil,
@@ -1,3 +1,3 @@
1
1
  module FacebookCoverResize
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,9 +1,17 @@
1
1
  module FacebookCoverResize
2
2
  module ViewHelpers
3
3
  def event_cover_tag(args)
4
- dims = FacebookCoverResize.compute(original: args[:original], offsets: args[:offsets], width: args[:width])
4
+ tag_generator(args.update(ratio: 1.91))
5
+ end
6
+
7
+ def account_cover_tag(args)
8
+ tag_generator(args.update(ratio: 2.66))
9
+ end
10
+
11
+ def tag_generator(args)
12
+ dims = FacebookCoverResize.compute(original: args[:original], offsets: args[:offsets], width: args[:width], ratio: args[:ratio])
5
13
  width = args[:width].to_i
6
- height = (width / 1.91).ceil
14
+ height = (width / args[:ratio]).ceil
7
15
  source = args[:source]
8
16
 
9
17
  content_tag(:div,
@@ -13,6 +21,5 @@ module FacebookCoverResize
13
21
  style: "width: #{width}px !important; height: #{height}px !important; overflow: hidden !important;position: relative !important; padding:0 !important"
14
22
  )
15
23
  end
16
-
17
24
  end
18
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook_cover_resize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - guillaume barillot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description: Compute width/size and offsets x/y for Facebook events cover image
55
+ description: Compute width/size and offsets x/y for Facebook cover images
56
56
  email:
57
57
  - gbarillot@gmail.com
58
58
  executables: []
@@ -97,5 +97,5 @@ rubyforge_project:
97
97
  rubygems_version: 2.4.8
98
98
  signing_key:
99
99
  specification_version: 4
100
- summary: Compute width/size and offsets x/y for Facebook events cover image
100
+ summary: Compute width/size and offsets x/y for Facebook cover images
101
101
  test_files: []