lk/vision/imagemagick.md

117 lines
2.0 KiB
Markdown
Raw Permalink Normal View History

2022-01-16 18:20:39 +00:00
---
title: "imagemagick"
2022-01-26 22:35:07 +00:00
tags: [ "Documentation", "Vision" ]
2022-01-16 18:20:39 +00:00
---
2020-01-02 00:04:35 +00:00
[Source](http://lxlinux.com/imagemagick.html)
Convert jpg to png.
```bash
convert image.jpg image.png
```
2020-01-02 00:04:35 +00:00
```bash
convert image.jpg -quality 50 image.jpg
```
2020-01-02 00:04:35 +00:00
'Quality' must be from 1 to 100.
```bash
convert -resize 50% image.jpg image2.jpg
```
2020-01-02 00:04:35 +00:00
Resizing only changes jpegs. Change a png with:
```bash
convert input.png png8:out.png
```
2020-01-02 00:04:35 +00:00
# Invert Colours
```bash
convert input.jpg output.jpg -negate
```
2020-01-02 00:04:35 +00:00
# Make Images Smaller
```bash
convert image.jpg -resize 25% output.jpg
```
2020-01-02 00:04:35 +00:00
# Trim images to border
2022-01-26 22:35:07 +00:00
2020-01-02 00:04:35 +00:00
This is generally used for transparrent images.
```bash
convert -trim image.png output.png
```
2020-01-02 00:04:35 +00:00
Make the white of an image transparrent.
```bash
convert -transparent white -fuzz 10% input.png output.png
```
2020-01-02 00:04:35 +00:00
The 'fuzz' option tells the computer that 'close to white' is fine. You might want to use 20% or higher fuzz.
## Dropshadow
```bash
`convert <input file> \( +clone -background black -shadow 50x8+0+5 \) +swap -background none -layers merge +repage <output file>`
```
2020-01-02 00:04:35 +00:00
# Convert every jpg in directory to png
```bash
mogrify -format png *.jpg
```
2020-01-02 00:04:35 +00:00
# Printing Words
# Mass convert
2020-11-29 01:22:51 +00:00
This script converts all jpg files in a directory to svg.
2020-01-02 00:04:35 +00:00
```
2020-11-29 01:22:51 +00:00
for i in *jpg
do convert "$i" $(ls "$i" | sed s#jpg\$#svg#)
2020-01-02 00:04:35 +00:00
done
```
2021-02-05 17:08:39 +00:00
# SVG
The above script has crappy results.
It's better to use potrace.
```
2022-08-18 00:25:38 +00:00
$convert -flatten input.jpg output.ppm
2021-02-05 17:08:39 +00:00
$potrace -s output.ppm -o svgout.svg
```
2020-01-02 00:04:35 +00:00
# Writing Words
[docs](https://www.imagemagick.org/Usage/text/)
See your installed fonts:
```bash
convert -list font
```
2020-01-02 00:04:35 +00:00
Make na image showing day of the week:
```bash
convert -fill blue -font Sauce-Code-Pro-Semibold-Nerd-Font-Complete-Mono -gravity center -pointsize 79 label:$(date +%A) day.png
```
2020-01-02 00:04:35 +00:00
2020-07-09 15:44:38 +00:00
Make a meme:
2020-01-02 00:04:35 +00:00
```bash
convert inputmemeimage.png -font impact -fill white -pointsize 84 -stroke black -strokewidth 3 -gravity north -annotate +0+20 'TOP MEME TEXT' -gravity south -annotate +0+20 'BOTTOM MEME TEXT' outputmemeimage.png
```
2020-01-02 00:04:35 +00:00