它是关于 RMagick 和 Ruby On Rails 的。
我执行以下操作:
image = params[:image]
# params[:image] is the image from the file-form.
name = image.original_filename.scan(/[^\/\\]+/).last
name = dir + t.day.to_s + t.month.to_s + t.year.to_s + t.hour.to_s + t.min.to_s + t.sec.to_s + name
f = File.new(name, "wb")
f.write image
f.close
image = Magick::Image.read(name)
image = image.resize_to_fit(200, 250)
f = File.new(name, "wb")
f.write image.to_blob
f.close
我真的需要先保存然后更改吗?不仅要改变大小,还要改变文件类型呢?我想要一个 60% 质量的 JPG。
这个错误是什么意思?
Magick::ImageMagickError (Improper image header `public/images/avatars/Joern/83201018458ich2_kleiner.png'):
请帮我。
你的,乔恩。