Skip to content

Instantly share code, notes, and snippets.

@michalkorzawski
Created October 23, 2022 22:06
Show Gist options
  • Save michalkorzawski/342e0c263166a0bb10004bbcf034b86f to your computer and use it in GitHub Desktop.
Save michalkorzawski/342e0c263166a0bb10004bbcf034b86f to your computer and use it in GitHub Desktop.
# app/services/image_converter.rb
class ImageConverter
def initialize(tempfile:, width: nil, height: nil, type: 'jpg')
@tempfile = tempfile
@width = width
@height = height
@type = type
end
def call
ImageProcessing::MiniMagick.source(@tempfile)
.resize_to_limit(@width, @height)
.convert(@type)
.call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment