开发者

Converting pdf's to images with Imagemagick + RMagic

I'm using papercli开发者_如何学Pythonp at the moment to convert pdf files to images.

My code looks something like this

  def convert_keynote_to_slides
    system('convert -size 640x300 ' +  keynote.queued_for_write[:original].path + ' ' + KEYNOTE_PATH + '/' + File.basename( self.keynote_file_name )+"%02d.png")

    slide_basename = File.basename( self.keynote_file_name )

    files = Dir.entries(KEYNOTE_PATH).sort
    for file in files
      #puts file if file.include?(slide_basename +'-')
      self.slides.build("slide" => "#{file}") if file.include?(slide_basename)
    end

  end

I'm sure this can be re-factored to work better.

My questions are:

Is there a way to figure out the progress of ImageMagick if not how would I put this into a delayed job as im worried this wont scale very well.

Can anyone point me in the direction as to how to make this code better / more efficient. The KEYNOTE_PATH points to a directory in public where all of the images are held in a single folder im not sure if I like this or not. What would probably be better is to assign a random name to each file.


I hope you're doing extensive filtering of keynote.queued_for_write[:original].path and File.basename( self.keynote_file_name ) input variables, so you're not susceptible to shell meta-character injection attacks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜