Last active
June 19, 2024 07:43
-
-
Save Neoklosch/d025d32af3bea8d7daedd72e0f1d6e0c to your computer and use it in GitHub Desktop.
Convert image with color from first pixel with imagemagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# Unzip all zip files | |
for f in *.zip; do unzip "$f" -d "${f%.*}"; done | |
# Move all jpgs to displate | |
find . \( -iname "*.jpg" ! -iname "*_hoodie.jpg" \) -mindepth 2 -type f -print -exec mv -f {} ../displate/ \; | |
cd ../displate | |
# Fix faulty file names | |
for f in *\ *; do mv -f "$f" "${f// /_}"; done | |
# Resize all displate files | |
for file in *.jpg; do | |
echo "converting displate file $file right now" | |
W=`identify "$file" | cut -f 3 -d " " | sed s/x.*//` # width | |
H=`identify "$file" | cut -f 3 -d " " | sed s/.*x//` # height | |
if [ "$W" -gt "$H" ] && [ "$W" != 6300 ]; then | |
convert $file -format '%[pixel:p{4,4}]' info:- | xargs -I{} convert $file -resize 6300x4500 -background {} -colorspace sRGB -gravity center -extent 6300x4500 $file | |
elif [ "$W" -le "$H" ] && [ "$H" != 6300 ]; then | |
convert $file -format '%[pixel:p{4,4}]' info:- | xargs -I{} convert $file -resize 4500x6300 -background {} -colorspace sRGB -gravity center -extent 4500x6300 $file | |
fi | |
done | |
cd ../zips | |
# Move all pngs to shirts | |
find . \( -iname "*.png" ! -iname "*_hoodie.png" \) -mindepth 2 -type f -print -exec cp {} ../shirts/ \; | |
cd ../shirts | |
# Fix faulty file names | |
for f in *\ *; do mv -f "$f" "${f// /_}"; done | |
cd ../zips | |
# Copy all pngs from shirts to redbubble | |
find . \( -iname "*.png" ! -iname "*_hoodie.png" \) -mindepth 2 -type f -print -exec cp {} ../redbubble/ \; | |
cd ../redbubble | |
# Resize all pngs in redbubble | |
for file in *.png; do | |
echo "converting redbubble file $file right now" | |
W=`identify "$file" | cut -f 3 -d " " | sed s/x.*//` # width | |
H=`identify "$file" | cut -f 3 -d " " | sed s/.*x//` # height | |
if [ "$W" -gt "$H" ] && [ "$W" != 6300 ]; then | |
convert $file -resize 7632x6480 -gravity center $file | |
elif [ "$W" -le "$H" ] && [ "$H" != 6300 ]; then | |
convert $file -resize 6480x7632 -gravity center $file | |
fi | |
done | |
cd ../zips | |
# Remove extracted folders | |
find . -iname '*.zip' -exec sh -c 'rm -Rf "${1%.*}"' _ {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment