Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
eef0bd0c
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
eef0bd0c
编写于
4月 23, 2018
作者:
J
Janko Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recommend using :resize_to_fit after all
上级
dc97f6c3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
17 addition
and
17 deletion
+17
-17
actionview/lib/action_view/helpers/asset_tag_helper.rb
actionview/lib/action_view/helpers/asset_tag_helper.rb
+2
-2
activestorage/README.md
activestorage/README.md
+1
-1
activestorage/app/models/active_storage/blob/representable.rb
...vestorage/app/models/active_storage/blob/representable.rb
+5
-5
activestorage/app/models/active_storage/preview.rb
activestorage/app/models/active_storage/preview.rb
+1
-1
activestorage/app/models/active_storage/variant.rb
activestorage/app/models/active_storage/variant.rb
+5
-5
activestorage/app/models/active_storage/variation.rb
activestorage/app/models/active_storage/variation.rb
+1
-1
guides/source/active_storage_overview.md
guides/source/active_storage_overview.md
+2
-2
未找到文件。
actionview/lib/action_view/helpers/asset_tag_helper.rb
浏览文件 @
eef0bd0c
...
...
@@ -325,9 +325,9 @@ def preload_link_tag(source, options = {})
#
# image_tag(user.avatar)
# # => <img src="/rails/active_storage/blobs/.../tiger.jpg" />
# image_tag(user.avatar.variant(resize
: "100x100"
))
# image_tag(user.avatar.variant(resize
_to_fit: [100, 100]
))
# # => <img src="/rails/active_storage/variants/.../tiger.jpg" />
# image_tag(user.avatar.variant(resize
: "100x100"
), size: '100')
# image_tag(user.avatar.variant(resize
_to_fit: [100, 100]
), size: '100')
# # => <img width="100" height="100" src="/rails/active_storage/variants/.../tiger.jpg" />
def
image_tag
(
source
,
options
=
{})
options
=
options
.
symbolize_keys
...
...
activestorage/README.md
浏览文件 @
eef0bd0c
...
...
@@ -99,7 +99,7 @@ Variation of image attachment:
```
erb
<%# Hitting the variant URL will lazy transform the original blob and then redirect to its new service location %>
<%=
image_tag
user
.
avatar
.
variant
(
resize
:
"100x100"
)
%>
<%=
image_tag
user
.
avatar
.
variant
(
resize
_to_fit:
[
100
,
100
]
)
%>
```
## Direct uploads
...
...
activestorage/app/models/active_storage/blob/representable.rb
浏览文件 @
eef0bd0c
...
...
@@ -10,7 +10,7 @@ module ActiveStorage::Blob::Representable
# Returns an ActiveStorage::Variant instance with the set of +transformations+ provided. This is only relevant for image
# files, and it allows any image to be transformed for size, colors, and the like. Example:
#
# avatar.variant(resize
: "100x100"
).processed.service_url
# avatar.variant(resize
_to_fit: [100, 100]
).processed.service_url
#
# This will create and process a variant of the avatar blob that's constrained to a height and width of 100px.
# Then it'll upload said variant to the service according to a derivative key of the blob and the transformations.
...
...
@@ -18,7 +18,7 @@ module ActiveStorage::Blob::Representable
# Frequently, though, you don't actually want to transform the variant right away. But rather simply refer to a
# specific variant that can be created by a controller on-demand. Like so:
#
# <%= image_tag Current.user.avatar.variant(resize
: "100x100"
) %>
# <%= image_tag Current.user.avatar.variant(resize
_to_fit: [100, 100]
) %>
#
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::RepresentationsController
# can then produce on-demand.
...
...
@@ -43,13 +43,13 @@ def variable?
# from a non-image blob. Active Storage comes with built-in previewers for videos and PDF documents. The video previewer
# extracts the first frame from a video and the PDF previewer extracts the first page from a PDF document.
#
# blob.preview(resize
: "100x100"
).processed.service_url
# blob.preview(resize
_to_fit: [100, 100]
).processed.service_url
#
# Avoid processing previews synchronously in views. Instead, link to a controller action that processes them on demand.
# Active Storage provides one, but you may want to create your own (for example, if you need authentication). Here’s
# how to use the built-in version:
#
# <%= image_tag video.preview(resize
: "100x100"
) %>
# <%= image_tag video.preview(resize
_to_fit: [100, 100]
) %>
#
# This method raises ActiveStorage::UnpreviewableError if no previewer accepts the receiving blob. To determine
# whether a blob is accepted by any previewer, call ActiveStorage::Blob#previewable?.
...
...
@@ -69,7 +69,7 @@ def previewable?
# Returns an ActiveStorage::Preview for a previewable blob or an ActiveStorage::Variant for a variable image blob.
#
# blob.representation(resize
: "100x100"
).processed.service_url
# blob.representation(resize
_to_fit: [100, 100]
).processed.service_url
#
# Raises ActiveStorage::UnrepresentableError if the receiving blob is neither variable nor previewable. Call
# ActiveStorage::Blob#representable? to determine whether a blob is representable.
...
...
activestorage/app/models/active_storage/preview.rb
浏览文件 @
eef0bd0c
...
...
@@ -38,7 +38,7 @@ def initialize(blob, variation_or_variation_key)
# Processes the preview if it has not been processed yet. Returns the receiving Preview instance for convenience:
#
# blob.preview(resize
: "100x100"
).processed.service_url
# blob.preview(resize
_to_fit: [100, 100]
).processed.service_url
#
# Processing a preview generates an image from its blob and attaches the preview image to the blob. Because the preview
# image is stored with the blob, it is only generated once.
...
...
activestorage/app/models/active_storage/variant.rb
浏览文件 @
eef0bd0c
...
...
@@ -27,7 +27,7 @@
# To refer to such a delayed on-demand variant, simply link to the variant through the resolved route provided
# by Active Storage like so:
#
# <%= image_tag Current.user.avatar.variant(resize
: "100x100"
) %>
# <%= image_tag Current.user.avatar.variant(resize
_to_fit: [100, 100]
) %>
#
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::RepresentationsController
# can then produce on-demand.
...
...
@@ -36,15 +36,15 @@
# has already been processed and uploaded to the service, and, if so, just return that. Otherwise it will perform
# the transformations, upload the variant to the service, and return itself again. Example:
#
# avatar.variant(resize
: "100x100"
).processed.service_url
# avatar.variant(resize
_to_fit: [100, 100]
).processed.service_url
#
# This will create and process a variant of the avatar blob that's constrained to a height and width of 100.
# Then it'll upload said variant to the service according to a derivative key of the blob and the transformations.
#
# You can combine any number of ImageMagick/libvips operations into a variant
. In addition to that, you can also us
e
#
any macros provided by the ImageProcessing gem (such as +resize_to_limit+).
# You can combine any number of ImageMagick/libvips operations into a variant
, as well as any macros provided by th
e
#
ImageProcessing gem (such as +resize_to_fit+):
#
# avatar.variant(resize_to_
lim
it: [800, 800], monochrome: true, flip: "-90")
# avatar.variant(resize_to_
f
it: [800, 800], monochrome: true, flip: "-90")
#
# Visit the following links for a list of available ImageProcessing commands and ImageMagick/libvips operations:
#
...
...
activestorage/app/models/active_storage/variation.rb
浏览文件 @
eef0bd0c
...
...
@@ -6,7 +6,7 @@
# In case you do need to use this directly, it's instantiated using a hash of transformations where
# the key is the command and the value is the arguments. Example:
#
# ActiveStorage::Variation.new(resize
: "100x100"
, monochrome: true, trim: true, rotate: "-90")
# ActiveStorage::Variation.new(resize
_to_fit: [100, 100]
, monochrome: true, trim: true, rotate: "-90")
#
# The options map directly to {ImageProcessing}[https://github.com/janko-m/image_processing] commands.
class
ActiveStorage::Variation
...
...
guides/source/active_storage_overview.md
浏览文件 @
eef0bd0c
...
...
@@ -353,7 +353,7 @@ original blob into the format you specified and redirect to its new service
location.
```
erb
<%=
image_tag
user
.
avatar
.
variant
(
resize
:
"100x100"
)
%>
<%=
image_tag
user
.
avatar
.
variant
(
resize
_to_fit:
[
100
,
100
]
)
%>
```
To switch to the Vips processor, you would add the following to
...
...
@@ -375,7 +375,7 @@ the box, Active Storage supports previewing videos and PDF documents.
<ul>
<%
@message
.
files
.
each
do
|
file
|
%>
<li>
<%=
image_tag
file
.
preview
(
resize
:
"100x100>"
)
%>
<%=
image_tag
file
.
preview
(
resize
_to_limit:
[
100
,
100
]
)
%>
</li>
<%
end
%>
</ul>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录