Ruby 返回语句
后照片后处理:后处理后照片Ruby 返回语句,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,后照片后处理:后处理后照片 def post_process_photo img = EXIFR::JPEG.new(photo.queued_for_write[:original].path) # error on this line return unless img self.width = img.width self.height = img.height self.model = img.model end 我正在使用一个名为EXIFR的ruby gem
def post_process_photo
img = EXIFR::JPEG.new(photo.queued_for_write[:original].path) # error on this line
return unless img
self.width = img.width
self.height = img.height
self.model = img.model
end
我正在使用一个名为EXIFR的ruby gem,它从JPEG文件中提取EXIF数据。EXIF数据只是有关图片的技术数据。因此,当我上传JPEG时,我的代码工作正常,但是任何其他图像类型都会导致它崩溃
EXIFR::ImagesController#create中的格式错误
找不到图像标记的开始
我假设如果img变量没有赋值,return语句将允许此操作,但情况似乎并非如此。您可以挽救错误并返回其他内容
def post_process_photo
begin
img = EXIFR::JPEG.new(photo.queued_for_write[:original].path) # error on this line
self.width = img.width
self.height = img.height
self.model = img.model
rescue EXIFR::MalformedJPEG
return nil
end
end