TonUINO-Covermaker (online)

Hallo zusammen,
Danke erst einmal für die Veröffentlichung des Scource Codes durch @Thorsten und die PowerShell Umsetzung von @Dave!

Obwohl ich bisher noch nicht mit ImageMagick gearbeitet habe, war es damit einfach, das in bash umzusetzen. Ich habe noch folgende Veränderung vorgenommen:

  1. Umstellen der Berechnung: Ich weiß nicht, wie und wann PHP rundet, aber ich habe vorausgesetzt, dass einfach die kleinere Dimension beibehalten wird und die andere entsprechend vergrößert wird. So werden keine „unnötigen“ Bildpunkte erzeugt und ich kann alle Rechnungen so umstellen, dass zuerst multipliziert und dann dividiert wird.
  2. Ich habe ein bischen im ImageMagick Handbuch gestöbert und glaube, dass ich die zweite temporäre Instanz (bzw. die zweite Temporärdatei) los geworden bin.
  3. Die Temporärdatei wird am Ende gelöscht.

Daher übergebe ich hiermit das Skriptchen zum Testen und Probieren - aber ohne Garantie!

#!/bin/bash
#
# Create image with aspect ratio according to preset size.
# Offline version of http://voss.earth/TonUINO-Covermaker/
# See description/discussion in
# http://discourse.voss.earth/t/nutzt-einer-den-tonuino-covermaker-bzw-hat-den-mal-jemand-probiert
#
# Command line Parameter:
# $1 - Source file
# $2 - Blur operator (optional), see
#    https://www.imagemagick.org/script/command-line-options.php#gaussian-blur


#
# Configuration
#

# Destination size (choose unit to get integer values, e.g. 0.1mm)
# These values match Herma No. 5028, giving a ratio of 1.649606299.
dstSizeX=838
dstSizeY=508

# Default blur operator (used when $2 is not specified)
blurDefault=0x4                         

# Temorary file for background
background=covermakerBackground.jpg


#
# No configuration below this line
#
##############################################################################


#
# Gather data
#

# Evaluate input file
file="$1"
if [ ! -f "$file" ]; then
    echo "File not found: $file"
    exit 1
fi

# Evaluate blur operator
blur=${2:-$blurDefault}


# Split input file name and build output file name
extension="${file##*.}"
filename="${file%.*}"
outputFile="${filename}_label.$extension"

# Get resolution from input file
inSizeX=$(identify -format "%[width]" "$file")
inSizeY=$(identify -format "%[height]" "$file")

# Make sure, we can make calculation with size
inSizeX=$((inSizeX))
inSizeY=$((inSizeY))

# Calculate resolution of output (including correct rounding)
if [ $((dstSizeX*inSizeY)) -gt $((inSizeX*dstSizeY)) ]; then
    # Theoretical formula for dstSizeX/dstSizeY > inSizeX/inSizeY:
    # yOut = yIn; xOut = xDest/yDest * yOut
    outSizeX=$(( (2*dstSizeX*inSizeY + dstSizeY) / (2*dstSizeY) ))
    outSizeY=$((inSizeY))
else
    # Theoretical formula for dstSizeX/dstSizeY <= inSizeX/inSizeY:
    # xOut = xIn; yOut = yDest/xDest * xOut
    outSizeX=$((inSizeX))
    outSizeY=$(( (2*dstSizeY*inSizeX + dstSizeX) / (2*dstSizeX) ))
fi

# Summary in one line (for processing multiple images)
echo -n "$file ${inSizeX}x${inSizeY} --$blur-> $outputFile ${outSizeX}x${outSizeY}"


#
# Do the work
#

# Build blurred background
convert -adaptive-resize "$((inSizeX/10))x$((inSizeY/10))!" \
        -gaussian-blur "$blur" \
        -adaptive-resize "$((outSizeX))x$((outSizeY))!" \
        -virtual-pixel mirror \
        "$file" "$background"

# Put the original image in the middle of the background and be done
convert "$background" "$file" \
        -gravity center -composite \
        -compose src-atop \
        -flatten \
        "$outputFile"


#
# Clean up
#

# Delete temporary file
rm "$background"

echo "."

Viel Erfolg damit!
Über Rückmeldung würde ich mich freuen - falls etwas nicht funktioniert, bräuchte ich zumindest die Breite und Höhe der Eingangs- und Ausgangsdatei.

2 „Gefällt mir“