I'm looking for the command and options to convert images (png, jpeg, whatever…) to 1bit/px bitmap image (similar to what happen when in photoshop when you convert it to bitmap). See example below
I'd like to do it programatically from within a rails app (e.g. RMagick or through ImageMagick)
The following works :
convert yo.jpg -remap pattern:gray30 mono.gif
but I' like to understand better what's happening, compared to what phosotsohp would do in that case; considering the many possibilities explained here (@roger_rowland thx for the link again)
In the end what I want to do is to have this "effect", and to enlarge the image without ending up with a blurry effect
ImageMagick can resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
If you have the free command-line tool ImageMagick installed on your computer, you can convert an HEIC file to any other format using the convert tool.
ImageMagick provides a fast, simple way to automate image resizing.
ImageMagick is a free and open source, feature-rich, text-based, and cross-platform image manipulation tool used to create, edit, compose or convert bitmap images. It runs on Linux, Windows, Mac Os X, iOS, Android OS, and many other operating systems.
-monochrome
This option uses some smart dithering and generates very visible output:
convert -monochrome in.png out.png
Documentation: http://www.imagemagick.org/Usage/quantize/#monochrome
Compare that to a simpler -threshold 50
transform:
convert -threshold 50 in.png out.png
which loses most of the image. We could likely have improved that with a better -threshold
value, but the beauty of -monochrome
is that it is smarter and often works without us having to guess anything.
Concrete example from: https://www.nasa.gov/mission_pages/galex/pia15416.html
wget -O orig.jpg http://www.nasa.gov/images/content/650137main_pia15416b-43_full.jpg
# Downsize to 400 height to have a reasonable file size for upload here.
convert orig.jpg -resize x400 in.jpg
convert -monochrome in.jpg out.jpg
convert -threshold 50 in.jpg threshold-50.jpg
in.jpg
out.jpg
threshold-50.jpg
Related questions:
Tested in Ubuntu 19.10, ImageMagick 6.9.10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With