Skip to content

Instantly share code, notes, and snippets.

@DevFatani
Created January 12, 2020 02:53
Show Gist options
  • Save DevFatani/fce467b175f86a167db5ee2ec2e711e7 to your computer and use it in GitHub Desktop.
Save DevFatani/fce467b175f86a167db5ee2ec2e711e7 to your computer and use it in GitHub Desktop.
Ruby RMagick
require 'RMagick'
def export_gif()
newGif = Magick::ImageList.new("images/ass.png", "images/ss.png", "images/gr.jpg", "images/image512.png")
newGif.write("animated.gif")
end
def read_image_properties()
img = Magick::Image.read("images/ss.png").first
puts " Format: #{img.format}"
puts " Geometry: #{img.columns}x#{img.rows}"
puts " Class: " + case img.class_type
when Magick::DirectClass
"DirectClass"
when Magick::PseudoClass
"PseudoClass"
end
puts " Depth: #{img.depth} bits-per-pixel"
puts " Colors: #{img.number_colors}"
puts " Filesize: #{img.filesize}"
puts " Resolution: #{img.x_resolution.to_i}x#{img.y_resolution.to_i} "+
"pixels/#{img.units == Magick::PixelsPerInchResolution ?
"inch" : "centimeter"}"
end
def minify_image_size()
img = Magick::Image.read("images/ss.png").first
puts "Before Filesize: #{img.filesize / 1000}"
img.minify!
img.write("ass_out.png")
puts "After Filesize: #{img.filesize / 1000}"
end
def check_image_alpah()
image = Magick::Image.read("images/ss.png").first
if image.alpha?
img_w = image.columns
img_h = image.rows
bg = Magick::Image.new(img_w, img_h) { self.background_color = "pink" } # create a white background
image = bg.composite(image, Magick::NorthWestGravity, 0, 0, Magick::OverCompositeOp) # compose
end
image.write("ass_out.png")
end
# export_gif
# read_image_properties
# minify_image_size
# check_image_alpah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment