Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip-qiniu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip-qiniu
Commits
d1d5f8ca
Commit
d1d5f8ca
authored
Sep 06, 2012
by
LI Daobing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add qiniu_image_tag
parent
531a133a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
3 deletions
+62
-3
README.md
+11
-1
lib/paperclip-qiniu.rb
+1
-0
lib/paperclip/qiniu/action_view_extensions/qiniu_image_path.rb
+19
-2
lib/paperclip/qiniu/action_view_extensions/qiniu_image_tag.rb
+31
-0
No files found.
README.md
View file @
d1d5f8ca
...
...
@@ -43,11 +43,21 @@ for more information on `qiniu_host`, read http://docs.qiniutek.com/v2/sdk/ruby/
```
ruby
class
Image
<
ActiveRecord
::
Base
attr_accessible
:file
has_attached_file
:file
,
:
styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
:path
=>
":class/:attachment/:id/:style
/:basename.:extension"
has_attached_file
:file
,
:
path
=>
":class/:attachment/:id
/:basename.:extension"
validates
:file
,
:attachment_presence
=>
true
end
```
*
show image in your view
```
erb
<%=
qiniu_image_tag
@image
.
file
.
url
,
:thumbnail
=>
'300x300>'
,
:quality
=>
80
%>
or
<%=
image_tag
qiniu_image_path
(
@image
.
file
.
url
,
:thumbnail
=>
'300x300>'
,
:quality
=>
80
)
%>
```
support options:
`thumbnail`
,
`gravity`
,
`crop`
,
`quality`
,
`rotate`
,
`format`
,
`auto_orient`
. for more information on these options, check the document: http://docs.qiniutek.com/v3/api/foimg/#fo-imageMogr
## Contributing
1.
Fork it
...
...
lib/paperclip-qiniu.rb
View file @
d1d5f8ca
require
"paperclip-qiniu/version"
require
'paperclip/storage/qiniu'
require
'paperclip/qiniu/action_view_extensions/qiniu_image_path'
if
defined?
(
ActionView
)
require
'paperclip/qiniu/action_view_extensions/qiniu_image_tag'
if
defined?
(
ActionView
)
lib/paperclip/qiniu/action_view_extensions/qiniu_image_path.rb
View file @
d1d5f8ca
...
...
@@ -3,11 +3,28 @@ module Paperclip
module
ActionViewExtensions
module
QiniuImagePath
def
qiniu_image_path
(
source
,
options
=
{})
options
=
options
.
clone
thumbnail
=
options
.
delete
(
:thumbnail
)
gravity
=
options
.
delete
(
:gravity
)
crop
=
options
.
delete
(
:crop
)
quality
=
options
.
delete
(
:quality
)
rotate
=
options
.
delete
(
:rotate
)
format
=
options
.
delete
(
:format
)
auto_orient
=
options
.
delete
(
:auto_orient
)
res
=
source
res
+=
"?imageMogr"
if
thumbnail
res
+=
"?imageMogr"
res
+=
"/thumbnail/
#{
CGI
.
escape
thumbnail
}
"
if
thumbnail
res
.
html_safe
res
+=
"/gravity/
#{
CGI
.
escape
gravity
}
"
if
gravity
res
+=
"/crop/
#{
CGI
.
escape
crop
}
"
if
crop
res
+=
"/quality/
#{
CGI
.
escape
quality
.
to_s
}
"
if
quality
res
+=
"/rotate/
#{
CGI
.
escape
rotate
.
to_s
}
"
if
rotate
res
+=
"/format/
#{
CGI
.
escape
format
.
to_s
}
"
if
format
res
+=
"/auto-orient"
if
auto_orient
if
res
.
end_with?
'?imageMogr'
source
else
res
end
end
end
end
...
...
lib/paperclip/qiniu/action_view_extensions/qiniu_image_tag.rb
0 → 100644
View file @
d1d5f8ca
module
Paperclip
module
Qiniu
module
ActionViewExtensions
module
QiniuImageTag
def
qiniu_image_tag
(
source
,
options
=
{})
options
.
symbolize_keys!
src
=
path_to_image
(
source
)
options
[
:src
]
=
qiniu_image_path
(
src
,
options
)
unless
src
=~
/^(?:cid|data):/
||
src
.
blank?
options
[
:alt
]
=
options
.
fetch
(
:alt
){
image_alt
(
src
)
}
end
if
size
=
options
.
delete
(
:size
)
options
[
:width
],
options
[
:height
]
=
size
.
split
(
"x"
)
if
size
=~
%r{^
\d
+x
\d
+$}
end
if
mouseover
=
options
.
delete
(
:mouseover
)
options
[
:onmouseover
]
=
"this.src='
#{
path_to_image
(
mouseover
)
}
'"
options
[
:onmouseout
]
=
"this.src='
#{
options
[
:src
]
}
'"
end
tag
(
"img"
,
options
)
end
end
end
end
end
ActionView
::
Base
.
send
:include
,
Paperclip
::
Qiniu
::
ActionViewExtensions
::
QiniuImageTag
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment