Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

SVGs are not handled by thumbnail processor correctly #1564

Closed
gustavoguimaraes opened this issue Jun 9, 2014 · 8 comments
Closed

SVGs are not handled by thumbnail processor correctly #1564

gustavoguimaraes opened this issue Jun 9, 2014 · 8 comments

Comments

@gustavoguimaraes
Copy link

When I upload and SVG to a model that accepts image attachments that uses the thumbnail processor, it has issues resizing the svg. This seems to be an imagemagic bug. It will claim success but generate an invalid svg file. This isn't a big deal since it's an SVG and the same file can be used for all sizes, however it makes using the uploaded image difficult.

I figured out how to skip post process if the file is an svg but I would like to be able to still use the same styles throughout the site regardless of the file type. Is there a way to specify a processor that would copy the file for each style? Or perhaps overload the styles for a file type so they always point to the "full" style?

Thanks

(ccing @ArmandoAmador @reconbot)

@asok
Copy link

asok commented Jul 4, 2014

I think I've stumbled on the same bug. @gustavoguimaraes could you please share with me your workaround?

@mister-burns
Copy link

I'm having a similar problem...anyone out there find a solution/workaround?

Thanks.

@maclover7
Copy link
Contributor

Hi everybody! Is this still an issue for you in Paperclip; I know this issue is from approximately 1 year ago. If it is still an issue, can you please provide the code that's causing you the error? Thanks!

@reconbot
Copy link

It came up in a client's project recently. I'll see if I can dig up a code example, but this is pretty self explanatory.

@reconbot
Copy link

I can confirm the bug still exist with something as simple as

class Company < ActiveRecord::Base
  has_attached_file :logo, styles: { invoice: '1800x200>', thumb: '300x200>' }
end

@cantonyselim
Copy link

So I have found a potential work-around to this problem. It is not perfect but it gets the job done in the sense that it displays the image in different styles correctly. Paperclip also saves a copy of the original so it still keeps that in case you need it.

has_attached_file :image, styles: { thumb: ["100x100>", :jpg] }

This will convert the styles to the format specified after the size when creating the styles. It will convert to and display the jpg or whatever file type you choose that ImageMagick can handle. Hope this is helpful to someone, I was stuck on this issue for 2 days.

@paulmenzel
Copy link

The problem seems to be in lib/paperclip/thumbnail.rb.

    # Performs the conversion of the +file+ into a thumbnail. Returns the Tempfile
    # that contains the new image.
    def make
      src = @file
      filename = [@basename, @format ? ".#{@format}" : ""].join
      dst = TempfileFactory.new.generate(filename)

      begin
        parameters = []
        parameters << source_file_options
        parameters << ":source"
        parameters << transformation_command
        parameters << convert_options
        parameters << ":dest"

        parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")

        success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path))
      rescue Cocaine::ExitStatusError => e
        raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
      rescue Cocaine::CommandNotFoundError => e
        raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
      end

      dst
    end

ImageMagick’s identify utility, seems to convert SVG files to a temporary PNG file and then use that for the calculations.

$ identify -format %m test.svg
PNG

@mike-burns
Copy link
Contributor

Looks like we found a workaround, closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants