Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gif are wrongly converted to jpg #794

Closed
Andrekra opened this issue Jun 15, 2015 · 1 comment
Closed

gif are wrongly converted to jpg #794

Andrekra opened this issue Jun 15, 2015 · 1 comment
Assignees

Comments

@Andrekra
Copy link

My use case involves using animated gifs. When a format is specified in show_alchemy_picture_path, it tries to converted the gif to an jpg. When dragonfly calls the 'convert' method on a gif to a jpg, it generates 1 jpg per frame, causing a massive slowdown and in the end the picture is not shown (not sure why now, maybe because the filename is different now, appended with the frame number).

The correct call would be convert 'images.gif[0]' image.png or convert -flatten images.gif image.png

The thumbnails in the admin, are stripped of their extension in

name: content.ingredient.urlname,

So it always uses the default format of png defined in routes. This would fix it:

image_tag(
        alchemy.thumbnail_path({
          id: content.ingredient.id,
          name: content.ingredient.urlname,
          sh: content.ingredient.security_token(image_options),
          format: content.ingredient.try(:image_file).try(:ext) || configuration(:image_output_format)
        }.merge(image_options)),
        alt: content.ingredient.name,
        class: 'img_paddingtop',
        title: _t(:image_name) + ": #{content.ingredient.name}"
      )

But this happens in various places, and not every view uses this helper

To fix generating multiple frames, I hooked into the alchemy/pictures_controller.rb#send_image method

 def send_image(image, format)
      request.session_options[:skip] = true
      ALLOWED_IMAGE_TYPES.each do |type|
        format.send(type) do
          options = []
          if type == 'jpeg'
            quality = params[:quality] || Config.get(:output_image_jpg_quality)
            options << "-quality #{quality}"
          end
          # Flatten gif sequence when converting to a different type
          if type != "gif" && image.ext == 'gif'
            options << "-flatten"
          end

          render text: image.encode(type, options.join(' ')).data
        end
      end
    end
@tvdeyen tvdeyen self-assigned this Sep 3, 2015
@tvdeyen
Copy link
Member

tvdeyen commented Sep 3, 2015

Confirm that displaying animated gifs are broken. Will provide a pull request that fixes that in the way that all thumbnails will get converted correctly into the target format.

But, I will not change the thumbnail format, because one does not want to really see the animation inside the thumbnail.

This would be visually distracting. The zoomed image in the library overlay should display the image in original format, so one can preview the animation if they prefer.

Thanks for your pictures controller fix, I will use that in my PR.

tvdeyen pushed a commit that referenced this issue Sep 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants