@@ -35,7 +35,7 @@ def save_attachments_with_pasted_images(attachments, author=User.current)
35
35
if attachments && attachments . is_a? ( Hash )
36
36
attachments . each do |key , value |
37
37
next unless key . start_with? ( '1000' )
38
- value [ 'file' ] = PastedImage . new ( value . delete ( 'data' ) , value . delete ( 'name' ) )
38
+ value [ 'file' ] = PastedImage . new ( value . delete ( 'data' ) , value . delete ( 'name' ) ) . raw
39
39
end
40
40
end
41
41
save_attachments_without_pasted_images ( attachments , author )
@@ -44,18 +44,15 @@ def save_attachments_with_pasted_images(attachments, author=User.current)
44
44
end
45
45
46
46
# Mimics uploaded file field data.
47
- class PastedImage
47
+ class PastedImage < StringIO
48
+
48
49
def initialize ( data , name )
49
- @raw = StringIO . new ( remove_alpha ( Base64 . decode64 ( data . to_s ) ) )
50
+ super ( remove_alpha ( Base64 . decode64 ( data . to_s ) ) )
50
51
@name = name . to_s . strip
51
52
@name = 'picture.png' if @name . blank?
52
53
@name += '.png' unless @name . end_with? ( '.png' )
53
54
end
54
55
55
- def size
56
- @raw . size
57
- end
58
-
59
56
def original_filename
60
57
@name
61
58
end
@@ -64,14 +61,7 @@ def content_type
64
61
"image/png"
65
62
end
66
63
67
- def read ( *args )
68
- @raw . read ( *args )
69
- end
70
-
71
- def eof?
72
- @raw . eof?
73
- end
74
-
64
+ protected
75
65
# remove alpha channel (because PDF export doesn't support PNGs with alpha channel,
76
66
# see https://github.com/peclik/clipboard_image_paste/issues/24)
77
67
def remove_alpha ( imgData )
@@ -95,7 +85,6 @@ def remove_alpha(imgData)
95
85
return imgData
96
86
end if not ( $clipboard_image_paste_remove_alpha && Object . const_defined? ( :Magick ) )
97
87
end
98
-
99
88
end
100
89
101
90
# Send patches - guarded against including the module multiple time
0 commit comments