Carrierwave 未使用 rmagick 调整版本大小
我正在尝试使用载波来管理图像。我的问题是我上传的图像的所有版本都已创建,但均为完整尺寸。代码:
class TechnologyImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Process files as they are uploaded:
#process :scale => [100, 100]
version :small do
process :resize_to_fit => [25,25]
end
version :medium do
process :resize_to_fit => [50,50]
end
end
所有图片版本均显示为原始上传的大小。
I am trying to use carrierwave to manage images. My problem is that all versions of the images I upload are created, but at the full size. Code:
class TechnologyImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Process files as they are uploaded:
#process :scale => [100, 100]
version :small do
process :resize_to_fit => [25,25]
end
version :medium do
process :resize_to_fit => [50,50]
end
end
All image versions are displayed as the size of the original upload.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的应用程序也有类似的问题。
虽然我想我发现,在使用版本时,
将每个“进程”设置为一个版本很有帮助......
否则我注意到有些方法正在“覆盖”其他方法......
奇怪的。
然后将变成 ::
有用
我希望这是“真实的”并且对其他用户Marin
I have a somehow similar problem with my app.
Though i think i figured out that, when using versions,
it is helpful to set every 'process' as a version...
Otherwise i've noticed that some methods were 'overwriting' others...
Bizarre.
which would then become ::
I hope this is 'true' and will be useful to other users
Marin
不确定你们是否因为与我相同的原因而遇到这个问题,但也许吧。
我需要将上传的文件移动到私人文件夹中,我相信您也这样做了。
上传后,我想删除缓存,我做了什么:
这样做的问题是,创建版本后,将触发 after :store ,因此应用程序会删除缓存目录,因此其他版本方法无法使用不再阅读该文件了。
对我来说,临时解决方案是将cache_dir 移动到私人文件夹。我稍后需要以不同的方式清空什么,我需要弄清楚,所以:
Not sure if you guys have this issue because of the same cause as I, but maybe.
I needed to move the uploaded files to a private folder, witch I'm sure you did as well.
After my upload I wanted to delete the cache what I did with:
The problem with this, is that after a version is created, the after :store will be triggered, so the app removes the cache directory, so the other version methods couldn't read that file anymore.
For me a temporal solution was to move the cache_dir to a private folder. What I need to empty later in a different way, that i'll need to figure out, so:
我的问题的解决方案是 Rails 环境在服务器上被命名为“staging”,在 Mac 上被命名为“development”。
文件 config/initializers/rierwave.rb 中的第 4 行(第 4 行)禁用名为“staging”的环境的载波处理。
为了使处理工作,我需要启用这一行:
The solution to my problem was that the rails environment was named 'staging' on the server and 'development' on the mac.
Line 4 at file config/initializers/carrierwave.rb (line 4) disables the carrierwave processing for environments named 'staging'.
In order to make the processing work, I needed to enable with this line: