6

Darkening an image with ImageMagick

 7 months ago
source link: https://akrabat.com/darkening-an-image-with-imagemagick/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Darkening an image with ImageMagick

darker-title-slide-1024x576.jpg

I regularly need to darken images for background use behind a title. I’ve been using a filter in Acorn, but finally decided to make it a script that uses ImageMagick so that I could simplify it all with Alfred. This is the script:

darken-image.sh

#!/usr/bin/env bash

if [ -z "$1" ]
then
  echo "Usage: darken-image  [contrast=40]"
  echo ""
  exit 1
fi

in_filename="$1"
amount=${2:-40}

# Set output filename to original filename with "-darker" appended
extension="${in_filename##*.}"
name="${in_filename%.*}"
out_filename="${name}-darker.${extension}"

# Use ImageMagick to darken the original image and create the new file
convert "$in_filename" -fill black -colorize "$amount"% "$out_filename"

echo "Darkened image created: $out_filename"

It’s not very complicated, though I did have to look up Bash’s parameter expansion again as I always forget it!

The actual image processing with ImageMagick’s convert application using colorize operator to blend the black fill colour into the image, which results in a darker image. I set a default of 40, but this can be changed on the command line as some images need a different value.

Little automation scripts like this make life much easier.

This article was posted on 15 January 2024 in Computing


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK