Sha256: 030eb43ba8371d8e49d2fcd46cc6f06f91c6f0d50773d3c91008cfdc83644171

Contents?: true

Size: 1016 Bytes

Versions: 2

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true
# typed: strict

require "image_size"
require "base64"
require "shellwords"
require_relative "base"

module Mayu
  module Resources
    module Generators
      class Image < Base
        extend T::Sig

        sig do
          params(
            source_path: String,
            version: Types::Image::ImageDescriptor
          ).void
        end
        def initialize(source_path, version)
          @source_path = source_path
          @version = version
        end

        sig { override.params(target_path: String).void }
        def process(target_path)
          return if File.exist?(target_path)

          require "rmagick"

          Console.logger.info(
            self,
            "Generating #{target_path} from #{@source_path}"
          )

          Magick::Image
            .read(@source_path)
            .first
            .resize_to_fit(@version.width)
            .write(target_path) { |options| options.quality = 80 }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mayu-live-0.0.6 lib/mayu/resources/generators/image.rb
mayu-live-0.0.5 lib/mayu/resources/generators/image.rb