facebook_cover_resize 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +7 -1
- data/README.md +26 -17
- data/facebook_cover_resize.gemspec +2 -2
- data/lib/facebook_cover_resize.rb +2 -2
- data/lib/facebook_cover_resize/version.rb +1 -1
- data/lib/facebook_cover_resize/view_helpers.rb +10 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae8b549158edc3e8266b43bc0bca3dd02623758b
|
4
|
+
data.tar.gz: 2a68f2c0b8a814e08d20a774e9597941b5d795b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b94ce8e7618abc4b4e9b4fbe5cf199cb4ea40b77cf5168f758a9c687e08ef9790ea8888e5c4beb5e2dd7d9ea7353a9bb7cf5255bb9ca3c41bb014dd7b1e6f92
|
7
|
+
data.tar.gz: 6122d32a491fb2ccc3cf907fd6e2711fe7fef13310248112d67348d01acc94afc0471a322ffba5528f58897c46fe104faf74b75f96e4e4ccfeedcd3f41238122
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# Facebook Cover Resize
|
2
2
|
|
3
|
-
|
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
|
+
[](https://travis-ci.org/gbarillot/facebook_cover_resize)
|
6
4
|
|
7
|
-
|
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
|
-
|
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
|
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
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
48
|
-
|
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
|
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: [
|
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
|
13
|
-
spec.description = "Compute width/size and offsets x/y for Facebook
|
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 /
|
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,9 +1,17 @@
|
|
1
1
|
module FacebookCoverResize
|
2
2
|
module ViewHelpers
|
3
3
|
def event_cover_tag(args)
|
4
|
-
|
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 /
|
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.
|
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-
|
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
|
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
|
100
|
+
summary: Compute width/size and offsets x/y for Facebook cover images
|
101
101
|
test_files: []
|