imagemagick - Ruby Rmagick: Crop/"Trim" excessive (white) space of image automatically -
i'm taking "screenshot" of html documents imgkit (https://github.com/csquared/imgkit). background always white (#ffffff).
imgkit taking 1200 x 1000 pixel big "screenshots", , might end lot of white space actual content of html documents may small.
are there built in functions in rmagick crop/trim excessive white space automatically?
the solution rmagick's trim method.
example
require "rubygems" require "rmagick" require "imgkit" include magick kit = imgkit.new('http://localhost/test.html') blob = kit.to_img(:png) img = magick::image.from_blob(blob).first img.trim! file.open("test.png", "w") { |f| f << img.to_blob }
Comments
Post a Comment