Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #89 S3 plugin compatibility #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions lib/clipboard_image_paste/attachment_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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