You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
version:coverdoprocess:convert_cover=>:pngenddefconvert_cover(format)manipulate!do |img| # this is ::MiniMagick::Image instanceimg.format(format.to_s.downcase,0)imgendend
The problem I noticed is a significant performance drop for large PDFs like books with tens/hundreds of pages which didn't make sense to me. Uploading one such book took about 9 seconds to process. So, I began tracing the problem.
First, I converted the first page directly using imagemagick and it ran in less than 1 second.
$ convert book.pdf[0] test-imagemagick.png
Then, I used MiniMagick directly from a rails console and it also ran in less than 1 second.
img=MiniMagick::Image.new('book.pdf')# takes about 1 secondimg.format('png',0)
Looking through the implementation i found that manipulate! uses MiniMagick::Image.open.
When I ran that in rails console, I had found the performance drop.
img=MiniMagick::Image.open('book.pdf')# takes about 9 seconds
Turns out, the MiniMagick::Image.open method makes a copy of the loaded file instead of manipulating it directly and that's most likely the reason for the performance drop.
Also, having different versions in the Uploader already makes copies with prefixes such as cover_before running manipulate!, doesn't it?
There might be other use cases that would be affected by this change, but I'm not sure. If I have more time, I can investigate the implications further.
The text was updated successfully, but these errors were encountered:
My use case is that I want to create image previews from the first page of multi-page PDF document uploads.
I've used @davidchristiandy's solution from here.
The problem I noticed is a significant performance drop for large PDFs like books with tens/hundreds of pages which didn't make sense to me. Uploading one such book took about 9 seconds to process. So, I began tracing the problem.
First, I converted the first page directly using
imagemagick
and it ran in less than 1 second.Then, I used
MiniMagick
directly from arails console
and it also ran in less than 1 second.Looking through the implementation i found that
manipulate!
uses MiniMagick::Image.open.When I ran that in
rails console
, I had found the performance drop.Turns out, the MiniMagick::Image.open method makes a copy of the loaded file instead of manipulating it directly and that's most likely the reason for the performance drop.
My question is, couldn't
manipulate!
just use MiniMagick::Image.new since the original file is being overridden anyway?Also, having different versions in the Uploader already makes copies with prefixes such as
cover_
before runningmanipulate!
, doesn't it?There might be other use cases that would be affected by this change, but I'm not sure. If I have more time, I can investigate the implications further.
The text was updated successfully, but these errors were encountered: