Skip to content

Commit

Permalink
Fixes peclik#89 S3 plugin compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
berga committed May 17, 2019
1 parent 3c03ef3 commit 6dde942
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions lib/clipboard_image_paste/attachment_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def save_attachments_with_pasted_images(attachments, author=User.current)
if attachments && attachments.is_a?(Hash)
attachments.each do |key,value|
next unless key.start_with?('1000')
value['file'] = PastedImage.new(value.delete('data'), value.delete('name'))
value['file'] = PastedImage.new(value.delete('data'), value.delete('name')).raw
end
end
save_attachments_without_pasted_images(attachments, author)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 6dde942

Please sign in to comment.