Skip to content

Instantly share code, notes, and snippets.

@david-prv
Last active May 24, 2022 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-prv/236c7e44b23f5fa71e4c2819276c9b0e to your computer and use it in GitHub Desktop.
Save david-prv/236c7e44b23f5fa71e4c2819276c9b0e to your computer and use it in GitHub Desktop.
Simple script to generate ppm files from jpegs using 'imagemagick' and pacman package manager
#! /bin/bash
# check for arguments
if [ $# -eq 0 ]
then
# no args passed
echo "Usage: ./convert_ppm.sh <input file> <output file>"
exit 1
fi
# check for imagemagick dependency
pacman -Qi imagemagick > /dev/null
if [ $? -ne 0 ]
then
# missing dependency
echo "Missing dependency 'imagemagick'. Installing..."
sudo pacman -S imagemagick --noconfirm
fi
# converting
convert $1 -compress none -set comment \"\" $2
sed -i '/^#/d' $2
@NeuralCoder3
Copy link

NeuralCoder3 commented May 22, 2022

One could eliminate duplicate code by moving the conversion code out as we want to convert the image in both cases (if ImageMagick is installed and if we freshly installed ImageMagick)

if [ $? -ne 0 ]
then
	# missing dependency
	echo "Missing dependency 'ImageMagick'. Installing..."
	sudo pacman -S imagemagick --noconfirm
fi

# converting
convert $1 -compress none -set comment \"\" $2
sed -i '/^#/d' $2

@david-prv
Copy link
Author

Of course you're right. But for me this didn't play a role for a script, that had the only purpose to free me from remembering command names :) But you've got a point anyway. For a script that has to be published in any professional sense, these "Blemishes" should have been changed in any case.

@david-prv
Copy link
Author

One could eliminate duplicate code by moving the conversion code out as we want to convert the image in both cases (if ImageMagick is installed and if we freshly installed ImageMagick)

if [ $? -ne 0 ]
then
	# missing dependency
	echo "Missing dependency 'ImageMagick'. Installing..."
	sudo pacman -S imagemagick --noconfirm
fi

# converting
convert $1 -compress none -set comment \"\" $2
sed -i '/^#/d' $2

I got some time and I have realized your suggestion for improvement :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment