JPG到PNG使用RMagick [英] JPG to PNG using RMagick
本文介绍了JPG到PNG使用RMagick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用RMagick将获取的图像从JPG转换为PNG,调整大小然后将其存储在S3上:
I'm trying to convert a fetched image from JPG to PNG using RMagick, resize it and then store it on S3:
thumb = Magick::Image.read("artist.jpg").first
thumb.write("artist.png")
thumb.crop_resized!(120, 120, Magick::CenterGravity)
AWS::S3::S3Object.store("image.png", thumb.to_blob, AWS_BUCKET, :content_type => 'image/png', :access => :public_read)
图像确实保存为png但是当我在预览中打开它时,文档类型仍然显示 JPEG图片。实际上,除非我将扩展名更改回.jpg,否则图像甚至不会在Photoshop中打开。我错过了什么吗?
The image does get saved as a png but when I open it in Preview, document type still says "JPEG image". In fact, the image won't even open in Photoshop unless I change the extension back to ".jpg". Am I missing something?
推荐答案
尝试明确设置格式:
thumb = Magick::Image.read("artist.jpg").first
thumb.format = "PNG"
thumb.write("artist.png")
thumb.crop_resized!(120, 120, Magick::CenterGravity)
AWS::S3::S3Object.store("image.png", thumb.to_blob, AWS_BUCKET, :content_type => 'image/png', :access => :public_read)
这篇关于JPG到PNG使用RMagick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文