ires 1.1.0 → 1.3.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/README.md +5 -5
- data/ext/ires/ires.go +19 -0
- data/ext/main.go +36 -29
- data/lib/ires/core.rb +5 -2
- data/lib/ires/service.rb +18 -11
- data/lib/ires/version.rb +1 -1
- data/lib/ires/view_helper.rb +4 -7
- data/shared/darwin/ires.h +19 -3
- data/shared/darwin/ires.so +0 -0
- data/shared/linux/ires.h +5 -1
- data/shared/linux/ires.so +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2042998a8a99e30b9d328bfb4e52993d2234fa18
|
4
|
+
data.tar.gz: a67df3fd4e441d1fa4314a2ab5008fe025016c31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 973d78a2170df39499f8e1b62bb5a501984aeaf58e48bc4e56f3d10344f6fd93754a3b1ce2a8ac24f8581ac79df5fdbcdbd847391181a0009b8db35063bdd32b
|
7
|
+
data.tar.gz: f744b48d1f87d9dcf2f2d33e2c518b3e9654e0017faf5217685f18cbab2b46fc3d77249e8b6e80d683e10b2e348c5182b4388cea8276bf66ed6cda5e61d8cc73
|
data/README.md
CHANGED
@@ -11,16 +11,16 @@
|
|
11
11
|
|
12
12
|
```erb
|
13
13
|
<!-- Usually -->
|
14
|
-
<%= ires_tag(
|
14
|
+
<%= ires_tag("image_01.jpg", width: 90, height: 120) %>
|
15
15
|
|
16
16
|
<!-- Using image_tag options -->
|
17
|
-
<%= ires_tag(
|
17
|
+
<%= ires_tag("http://example.com/image_02.jpg", width: 200, height: 200, Ires::Mode::CROP, alt: "example image") %>
|
18
18
|
```
|
19
19
|
|
20
20
|
### Get resize path
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
Ires::Service.path(
|
23
|
+
Ires::Service.path('<FULL IMAGE PATH>', width: 400, height: 300)
|
24
24
|
=> /ires/<resize image path>
|
25
25
|
```
|
26
26
|
|
@@ -47,7 +47,7 @@ Filter of resize image.
|
|
47
47
|
Default: **30days**
|
48
48
|
|
49
49
|
```erb
|
50
|
-
<%= ires_tag(
|
50
|
+
<%= ires_tag('/image.jpg', width: 400, height: 300, expire: 7.days) %>
|
51
51
|
```
|
52
52
|
|
53
53
|
### Saved directory
|
@@ -126,7 +126,7 @@ $ dep ensure
|
|
126
126
|
# Output to a shared object.
|
127
127
|
$ CGO_ENABLED=1 GOOS=linux go build -v -buildmode=c-shared -o shared/linux/ires.so ext/main.go
|
128
128
|
```
|
129
|
-
※ In the current Docker, you can build only linux environment.
|
129
|
+
※ In the current Docker, you can build only linux environment.
|
130
130
|
※ If you want to build in other environments, add GCC or install Go on the host side.🙇
|
131
131
|
|
132
132
|
### 2. Start rails server
|
data/ext/ires/ires.go
CHANGED
@@ -50,6 +50,25 @@ type (
|
|
50
50
|
}
|
51
51
|
)
|
52
52
|
|
53
|
+
// Init is ...
|
54
|
+
func Init(size Size, rType int, uri, dir, expire string) (i *Ires) {
|
55
|
+
i = &Ires{
|
56
|
+
Size: size,
|
57
|
+
ResizeType: ResizeType(rType),
|
58
|
+
URI: uri,
|
59
|
+
Dir: dir,
|
60
|
+
Expire: expire,
|
61
|
+
}
|
62
|
+
|
63
|
+
// If local image, True
|
64
|
+
i.CheckLocal()
|
65
|
+
|
66
|
+
// Delete the expiration date image
|
67
|
+
i.DeleteExpireImage()
|
68
|
+
|
69
|
+
return
|
70
|
+
}
|
71
|
+
|
53
72
|
// Resize is ...
|
54
73
|
func (i *Ires) Resize() (string, error) {
|
55
74
|
i.Mode = Resize
|
data/ext/main.go
CHANGED
@@ -10,42 +10,49 @@ import (
|
|
10
10
|
func init() {}
|
11
11
|
func main() {}
|
12
12
|
|
13
|
-
//export
|
14
|
-
func
|
15
|
-
uri :=
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Height: height,
|
23
|
-
},
|
24
|
-
ResizeType: ires.ResizeType(rType),
|
25
|
-
URI: uri,
|
26
|
-
Dir: dir,
|
27
|
-
Expire: expire,
|
13
|
+
//export resizeImagePath
|
14
|
+
func resizeImagePath(URI *C.char, width, height, rType int, Dir, Expire *C.char) *C.char {
|
15
|
+
uri, dir, expire := cToString(URI, Dir, Expire)
|
16
|
+
r := ires.Init(ires.Size{ Width: width, Height: height }, rType, uri, dir, expire)
|
17
|
+
|
18
|
+
distURI, err := r.Resize()
|
19
|
+
if err != nil {
|
20
|
+
log.Print(err)
|
21
|
+
return C.CString(r.URI)
|
28
22
|
}
|
23
|
+
return C.CString(distURI)
|
24
|
+
}
|
25
|
+
|
26
|
+
//export cropImagePath
|
27
|
+
func cropImagePath(URI *C.char, width, height, rType int, Dir, Expire *C.char) *C.char {
|
28
|
+
uri, dir, expire := cToString(URI, Dir, Expire)
|
29
|
+
r := ires.Init(ires.Size{ Width: width, Height: height }, rType, uri, dir, expire)
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
var distURI string
|
36
|
-
var err error
|
37
|
-
switch ires.Mode(mode) {
|
38
|
-
case ires.Resize:
|
39
|
-
distURI, err = r.Resize()
|
40
|
-
case ires.Crop:
|
41
|
-
distURI, err = r.Crop()
|
42
|
-
case ires.ResizeToCrop:
|
43
|
-
distURI, err = r.ResizeToCrop()
|
31
|
+
distURI, err := r.Crop()
|
32
|
+
if err != nil {
|
33
|
+
log.Print(err)
|
34
|
+
return C.CString(r.URI)
|
44
35
|
}
|
36
|
+
return C.CString(distURI)
|
37
|
+
}
|
38
|
+
|
39
|
+
//export resizeToCropImagePath
|
40
|
+
func resizeToCropImagePath(URI *C.char, width, height, rType int, Dir, Expire *C.char) *C.char {
|
41
|
+
uri, dir, expire := cToString(URI, Dir, Expire)
|
42
|
+
r := ires.Init(ires.Size{ Width: width, Height: height }, rType, uri, dir, expire)
|
45
43
|
|
44
|
+
distURI, err := r.ResizeToCrop()
|
46
45
|
if err != nil {
|
47
46
|
log.Print(err)
|
48
47
|
return C.CString(r.URI)
|
49
48
|
}
|
50
49
|
return C.CString(distURI)
|
51
50
|
}
|
51
|
+
|
52
|
+
// Convert *C.char to String
|
53
|
+
func cToString(uri, dir, expire *C.char) (u, d, e string){
|
54
|
+
u = C.GoString(uri)
|
55
|
+
d = C.GoString(dir)
|
56
|
+
e = C.GoString(expire)
|
57
|
+
return
|
58
|
+
}
|
data/lib/ires/core.rb
CHANGED
@@ -6,15 +6,18 @@ module Ires
|
|
6
6
|
extend FFI::Library
|
7
7
|
# NOTE: ires.so is golang object
|
8
8
|
ffi_lib File.expand_path("../../shared/#{Ires::Os.current}/ires.so", File.dirname(__FILE__))
|
9
|
+
|
9
10
|
# resize func
|
10
11
|
# Type:
|
11
12
|
# path: :string
|
12
13
|
# width: :int
|
13
14
|
# height: :int
|
14
15
|
# type: :int
|
15
|
-
# mode: :int
|
16
16
|
# dir: :string
|
17
17
|
# expire: :string
|
18
|
-
|
18
|
+
params = %i[string int int int string string]
|
19
|
+
attach_function :resizeImagePath, params, :string
|
20
|
+
attach_function :cropImagePath, params, :string
|
21
|
+
attach_function :resizeToCropImagePath, params, :string
|
19
22
|
end
|
20
23
|
end
|
data/lib/ires/service.rb
CHANGED
@@ -8,11 +8,15 @@ module Ires
|
|
8
8
|
class << self
|
9
9
|
# Resize image path
|
10
10
|
# @return [String]
|
11
|
-
def path(path
|
12
|
-
raise
|
11
|
+
def path(path, width: nil, height: nil, type: Type::ALL, mode: Mode::RESIZE, expire: 30.days)
|
12
|
+
raise StandardError, "#{path} is not string." unless path.kind_of?(String)
|
13
|
+
raise ArgumentError, "Either width or height is required." if width.nil? && height.nil?
|
13
14
|
os = Ires::Os.current
|
14
15
|
return nil if os.nil?
|
15
16
|
|
17
|
+
raise StandardError, "Nil location provided. Can't build URI." if path.nil?
|
18
|
+
return path if path.empty?
|
19
|
+
|
16
20
|
full_path = image_full_path(path.to_s)
|
17
21
|
|
18
22
|
# if no image or could not find file path then perform the same action as 'image_tag'
|
@@ -68,15 +72,18 @@ module Ires
|
|
68
72
|
# Image path
|
69
73
|
# @return [String]
|
70
74
|
def ires_image_path(ires_element)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
ires_element
|
76
|
-
|
77
|
-
ires_element
|
78
|
-
|
79
|
-
|
75
|
+
mode = ires_element[:mode]
|
76
|
+
ires_element.delete(:mode)
|
77
|
+
case mode
|
78
|
+
when Mode::RESIZE
|
79
|
+
Core.resizeImagePath(*ires_element.values)
|
80
|
+
when Mode::CROP
|
81
|
+
Core.cropImagePath(*ires_element.values)
|
82
|
+
when Mode::RESIZE_TO_CROP
|
83
|
+
Core.resizeToCropImagePath(*ires_element.values)
|
84
|
+
else
|
85
|
+
Core.resizeImagePath(*ires_element.values)
|
86
|
+
end
|
80
87
|
end
|
81
88
|
end
|
82
89
|
end
|
data/lib/ires/version.rb
CHANGED
data/lib/ires/view_helper.rb
CHANGED
@@ -8,21 +8,18 @@ module Ires
|
|
8
8
|
module ViewHelper
|
9
9
|
# Image resize
|
10
10
|
# @return [image_tag]
|
11
|
-
def ires_tag(path
|
12
|
-
|
13
|
-
|
14
|
-
image = Ires::Service.path(
|
15
|
-
path: path,
|
11
|
+
def ires_tag(path, width: nil, height: nil, type: Type::ALL, mode: Mode::RESIZE, expire: 30.days, **option)
|
12
|
+
image_path = Ires::Service.path(
|
13
|
+
path,
|
16
14
|
width: width || 0,
|
17
15
|
height: height || 0,
|
18
16
|
mode: mode,
|
19
17
|
type: type,
|
20
18
|
expire: expire
|
21
19
|
)
|
22
|
-
return nil if image.nil?
|
23
20
|
|
24
21
|
# Set image_tag
|
25
|
-
image_tag(
|
22
|
+
image_tag(image_path, option)
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
data/shared/darwin/ires.h
CHANGED
@@ -1,7 +1,19 @@
|
|
1
|
-
/*
|
1
|
+
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
2
2
|
|
3
3
|
/* package command-line-arguments */
|
4
4
|
|
5
|
+
|
6
|
+
#line 1 "cgo-builtin-prolog"
|
7
|
+
|
8
|
+
#include <stddef.h> /* for ptrdiff_t below */
|
9
|
+
|
10
|
+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
11
|
+
#define GO_CGO_EXPORT_PROLOGUE_H
|
12
|
+
|
13
|
+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
14
|
+
|
15
|
+
#endif
|
16
|
+
|
5
17
|
/* Start of preamble from import "C" comments. */
|
6
18
|
|
7
19
|
|
@@ -38,7 +50,7 @@ typedef double _Complex GoComplex128;
|
|
38
50
|
*/
|
39
51
|
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
40
52
|
|
41
|
-
typedef
|
53
|
+
typedef _GoString_ GoString;
|
42
54
|
typedef void *GoMap;
|
43
55
|
typedef void *GoChan;
|
44
56
|
typedef struct { void *t; void *v; } GoInterface;
|
@@ -53,7 +65,11 @@ extern "C" {
|
|
53
65
|
#endif
|
54
66
|
|
55
67
|
|
56
|
-
extern char*
|
68
|
+
extern char* resizeImagePath(char* p0, GoInt p1, GoInt p2, GoInt p3, char* p4, char* p5);
|
69
|
+
|
70
|
+
extern char* cropImagePath(char* p0, GoInt p1, GoInt p2, GoInt p3, char* p4, char* p5);
|
71
|
+
|
72
|
+
extern char* resizeToCropImagePath(char* p0, GoInt p1, GoInt p2, GoInt p3, char* p4, char* p5);
|
57
73
|
|
58
74
|
#ifdef __cplusplus
|
59
75
|
}
|
data/shared/darwin/ires.so
CHANGED
Binary file
|
data/shared/linux/ires.h
CHANGED
@@ -65,7 +65,11 @@ extern "C" {
|
|
65
65
|
#endif
|
66
66
|
|
67
67
|
|
68
|
-
extern char*
|
68
|
+
extern char* resizeImagePath(char* p0, GoInt p1, GoInt p2, GoInt p3, char* p4, char* p5);
|
69
|
+
|
70
|
+
extern char* cropImagePath(char* p0, GoInt p1, GoInt p2, GoInt p3, char* p4, char* p5);
|
71
|
+
|
72
|
+
extern char* resizeToCropImagePath(char* p0, GoInt p1, GoInt p2, GoInt p3, char* p4, char* p5);
|
69
73
|
|
70
74
|
#ifdef __cplusplus
|
71
75
|
}
|
data/shared/linux/ires.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ires
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enta0701
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|