title: Paperclip don't generate styles and original image appears as broken
body: <p>I having a <strong>big</strong> issue here. I really tried, but I can't solve this problem by myself, so I hope people can help me here.</p>
  <p>Before talk about my problem, I must say I'm using <a href="https://github.com/thoughtbot/paperclip" rel="nofollow noreferrer">Paperclip</a> and <a href="https://github.com/csquared/IMGKit" rel="nofollow noreferrer">IMGKit</a> in my Project, but I think the problem is with Paperclip.</p>
  <p>I create a <code>Rails Task</code> to take snapshots from the home page of some sites. Sometime ago everything is working fine, but now everything goes down. I import my real database from Heroku to localhost  (without any images and migrations of paperclip), run the migrations, delete all old files from 'public/system' and run my task again (to take snapshot of all websites).</p>
  <p><img src="https://i.stack.imgur.com/5Qg8F.png" alt="enter image description here" /></p>
  <p><strong>So, now I have:</strong></p>
  <ul>
  <li>The paths and original images are generated, but when I try to load them in View, this just show as a broken image.</li>
  <li>Paperclip doesn't generate the path and converted images of <code>:styles</code>.</li>
  <li>Sites that don't have image, I can see my default image correctly.</li>
  <li>ImageMagick seems to be working, I try convert some images and worked like a charm.</li>
  </ul>
  <hr>
  <p>Let's take a look at the code. Assume that I'm running a task that will perform this task to all sites in my database. The sites are called &quot;items&quot; in my architecture.</p>
  <h2>Development.rb</h2>
  <pre><code>#config/environments/development.rb
  
  # &quot;which convert&quot; give me this path
  Paperclip.options[:command_path] = &quot;/usr/local/bin/&quot; 
  </code></pre>
  <h2>Item.rb (model)</h2>
  <p>My task just call &quot;object.save&quot; of every site in the DB, so my code starts on <code>before_save</code>.</p>
  <pre><code>has_attached_file :image,
      :styles =&gt; { :small =&gt; &quot;200x147#&quot; }, 
      :convert_options =&gt; { :small =&gt; &quot;-quality 75 -strip&quot; },
      :default_url =&gt; '/images/:style/bitcoin-earth.jpg'
  
  before_save :generate_data
  def generate_data
      self.image = get_image(self.id, self.url_original)
  end
  
  # Take snapshot of the website
  def get_image(filename, link)       
     kit = IMGKit.new(link.to_s, :quality =&gt; 100, :width =&gt; 1024, :height =&gt; 768)
  
     file  = Tempfile.new([&quot;template_#{filename}&quot;, 'png'], 'tmp',
                       :encoding =&gt; 'ascii-8bit')
     
     file.write(kit.to_img(:png))
     file.flush
     return file
   end
  </code></pre>
  <h2>View</h2>
  <pre><code>&lt;%= image_tag store.image.url %&gt;
  </code></pre>
  <h2>Gemfile</h2>
  <pre><code>gem &quot;paperclip&quot;
  </code></pre>
  <hr>
  <p>If I try to run <code>rake paperclip:refresh:missing_styles</code>, the task finish very fast without any error. But if I try to run <code>rake paperclip:refresh CLASS=Item</code> I got:</p>
  <pre><code>Image Paperclip::Errors::NotIdentifiedByImageMagickError
  </code></pre>
  <p>And yes, I already search for it and I didn't found a solution for my case.</p>
  <hr>
  <h2>A little tip?</h2>
  <p>When I &quot;inspect element&quot; in my project and try to see the source of the item image, I saw:</p>
  <pre><code>http://localhost:3000/public/system/items/images/000/000/216/original/template_21620140109-14507-1c0yszzpng?1389305824
  </code></pre>
  <p><img src="https://i.stack.imgur.com/Gq5gV.png" alt="enter image description here" /></p>
  <p>But if I go to my project folder, I just see a image called <code>template_21620140109-21209-1yls03opng</code>. Note that doesn't exist any &quot;?1389305824&quot; there. See the image above.</p>
  <p>Well, I think that's it. What can be the problem? I really need solve this issue, please, help me :/</p>
  <hr>
  <h2>[ Edited on Jan 10, 2013 ]</h2>
  <p><strong>Item.rb (model)</strong>:</p>
  <pre><code>before_save :generate_data
  def generate_data
      file = File.open(get_image(self.id, self.url_original))
      self.image = file
      file.close
  end
  
  def get_image(filename, link)
      kit = IMGKit.new(link.to_s, :quality =&gt; 100,
                                  :width =&gt; 1024, :height =&gt; 768)
  
      file  = Tempfile.new([&quot;template_#{filename}&quot;, '.png'], 'tmp',
                           :encoding =&gt; 'ascii-8bit')
      file.write(kit.to_img(:png))
      file.flush
      return file
  end
  </code></pre>
  <p>Now I don't have any error on console while getting images and saving on DB, but Paperclip still don't generate my :styles. When I go to <code>log/development.log</code>, I can see this error, but I don't know what I can do to solve:</p>
  <pre><code>Command :: file -b --mime 'tmp/template_24320140110-17577-80zj1c.png'
  Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/template_24320140110-17577-80zj1c20140110-17577-mqa2q3.png[0]'
  [paperclip] An error was received while processing: #&lt;Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError&gt;
  </code></pre>
  <p>I think we're getting closer, please, keep helping me :)</p>