From 28224413c8b759d62db654796b2bceecd220c0e0 Mon Sep 17 00:00:00 2001 From: Marco Bergantin Date: Fri, 17 May 2019 16:50:52 +0200 Subject: [PATCH] Fixes #89 S3 plugin compatibility --- lib/clipboard_image_paste/attachment_patch.rb | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/clipboard_image_paste/attachment_patch.rb b/lib/clipboard_image_paste/attachment_patch.rb index 5cfc7c0..4253510 100644 --- a/lib/clipboard_image_paste/attachment_patch.rb +++ b/lib/clipboard_image_paste/attachment_patch.rb @@ -44,18 +44,15 @@ def save_attachments_with_pasted_images(attachments, author=User.current) end # Mimics uploaded file field data. - class PastedImage + class PastedImage < StringIO + def initialize(data, name) - @raw = StringIO.new(remove_alpha(Base64.decode64(data.to_s))) + super(remove_alpha(Base64.decode64(data.to_s))) @name = name.to_s.strip @name = 'picture.png' if @name.blank? @name += '.png' unless @name.end_with?('.png') end - def size - @raw.size - end - def original_filename @name end @@ -64,14 +61,7 @@ def content_type "image/png" end - def read(*args) - @raw.read(*args) - end - - def eof? - @raw.eof? - end - + protected # remove alpha channel (because PDF export doesn't support PNGs with alpha channel, # see https://github.com/peclik/clipboard_image_paste/issues/24) def remove_alpha(imgData) @@ -95,7 +85,6 @@ def remove_alpha(imgData) return imgData end if not ($clipboard_image_paste_remove_alpha && Object.const_defined?(:Magick)) end - end # Send patches - guarded against including the module multiple time