TonUINO-Covermaker (online)

OK Danke für die Antwort.
Da ich aber nicht viel Ahnung davon habe, wäre ich für etwas unter die Arme greifen Dankbar.
Was muss ich machen damit ich das unter Windows zu laufen bekomme?
Danke

Erstmal musst du ImageMagick installieren: https://imagemagick.org/script/download.php
Je nach System in 32 oder 64 bit.
Im Installationsassistenten sicher stellen, dass die „Tools“ oder „Legacy Tools“ (weiß es grad nicht aus dem Kopf wie die Option genau hieß) mit installiert werden. Die werden für das Skript benötigt (s.u.: „convert“ und „identify“). Außerdem muss ImageMagick zur PATH Umgebungsvariablen hinzugefügt werden. Auch dafür bietet der Assistent eine Option.

Anschließend kannst du die Powershell starten und mittels dem Befehl
cd C:\Hier\liegen\die\Bilder
in den Ordner wechseln, wo deine Bilder liegen.

Im Prinzip kannst du den Code hier direkt kopieren, in die Powershell einfügen und nochmal Enter drücken. Alternativ kannst du natürlich vorher auch noch etwas an der Konfiguration schrauben. Was dann passiert ist folgendes:
Es werden im aktuellen Ordner alle jp*g Dateien (vermutlich ginge es auch mit anderen Bildformaten) gesucht und dann aus jedem einzelnen Bild ein Cover nach dem Vorbild des TonUINO Covermakers erstellt. Die Originaldateien werden nicht verändert, es wird jeweils eine neue Datei nach dem Schema „TonUINO_Cover_[Originaldateiname]“ erstellt.

### Konfiguration ###
$height_param=508
$width_param=838
$blur_param="0x4"
###

$background="covermakerBackground.jpg"
$files=gci -file -name *.jp*g
foreach ($file in $files)
{
$targetfile="TonUINO_Cover_$file"
$sizex=identify -format "%[width]" "$file"
$sizex=$sizex -as [int]
$sizey=identify -format "%[height]" "$file"
$sizey=$sizey -as [int]

if ( $width_param*$sizey -gt $sizex*$height_param )
{
$outSizeX=(2*$width_param*$sizey + $height_param) / (2*$height_param) -as [int]
$outSizeY=$sizey
}
else {
$outSizeX=$sizex
$outSizeY=(2*$height_param*$sizex + $width_param) / (2*$width_param) -as [int]
}

$resize1="$($sizex/10)" + "x" + "$($sizey/10)" + "!"
$resize2="$outSizeX" + "x" + "$outSizeY" + "!"
convert -adaptive-resize "$resize1" -gaussian-blur "$blur_param" -adaptive-resize "$resize2" -virtual-pixel mirror "$file" "$background"

convert "$background" "$file" -gravity center -composite -compose src-atop -flatten "$targetfile" 

remove-item $background
}
1 „Gefällt mir“

Danke schonmal.
Das mit dem Tool habe ich hinbekommen, nur sind die Bilder jetzt schwarz Weiß. Wie kann ich das umstellen?

Da bin ich jetzt ehrlich gesagt etwas ratlos. Du hast den Code in der Powershell ausgeführt und es wurden Dateien erstellt deren Name mit „TonUINO_Cover_“ beginnt? Dann sind zumindest die ImageMagick Befehle anscheinend durchgelaufen. Die erstellten Bilder sind dann vom eigentlichen Bildinhalt korrekt, aber statt in Farbe sind sie schwarz-weiß? Gab es beim Ausführen in der Powershell irgend eine Ausgabe? Wie ist denn die Ausgabe von „convert -version“?

Ich habe den Code mal etwas angepasst, weil Dateien mit Leerzeichen nicht konvertiert wurden und der „blur“ Parameter nicht übergeben wurde, aber dein Problem klingt nach was ganz anderem. Auf der ImageMagick Seite gibt es noch den Hinweis, dass man bei Problemen die Visual C++ Redistributable installieren soll (https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads).

Richtig. Powershell läuft durch, erstellt die Dateien und gibt die Datei mit TonUINO_Cover*** wieder aus. Nur dieses ist dann schwarz weiß. Ändere ich folgende Zeile

convert -size "$($sizex*$ratio)""x""$sizey" xc:black "im_out.jpg"

in

convert -size "$($sizex*$ratio)""x""$sizey" xc:blue "im_out.jpg"

ist alles farbig.

Nur das kann doch nicht das Problem sein.

1 „Gefällt mir“


im_background


im_out


im_out2

Ist ja merkwürdig. Bei mir funktioniert das auf 2 verschiedenen Systemen genau so. Der Befehl erstellt ja nur ein schwarzes Bild, was als Grundlage für die weiteren Schritte genutzt wird und ich hatte es einfach so aus Thorstens php Code übernommen. Vermutlich ist dein ImageMagick der Meinung, dass man bei einem schwarzen Bild im weiteren Verlauf einfach keine Farbe braucht. Das Verhalten kann sich ja von Version zu Version immer mal etwas unterscheiden. So gut kenne ich mich da aber auch nicht aus.

Ich habe jetzt die Berechnung und die Aufrufe von @LeffSpike einfach mal in Powershell umgesetzt. Besten Dank für die Weiterentwicklung :slight_smile:
Netterweise kommt diese Lösung mit wesentlich weniger temporären Dateien / Zwischenschritten aus und auch bei nicht quadratischen Bildern sowohl im Hoch- als auch Querformat ist das Ergebnis so weit ich sehen konnte super.
Löst es das Problem, wenn du den nochmal abgeänderten Code aus meinem Post oben nimmst?

Ich muss diesen Thread leider noch mal auf machen.
Lassen sich die verlinkten Sticke auch im Canon Selphy CP710 verwenden? Das ist einer der ersten dieser Druckerserie und so einer schlummert noch bei mir im Schrank. Ich habe leider nirgendwo eine Antwort finden können.

Hab da mal eine Frage, weiß nicht ob ich einfach zu blind bin…
Die Cover werden bei mir ohne Probleme erstellt, aber ich kann das Cover nur als .php abspeichern. Wie kriege ich denn von dem erstellten Cover eine .jpeg?

Ja, das ist irgendwie geändert worden. Das war früher nicht so.
Du kannst die Datei als php speichern und anschließend im Explorer aus der Dateiendung .php eine .png machen.

@Thorsten Kannst du das evtl. anpassen?

1 „Gefällt mir“

Das liegt am Browser. Wenn ich das Bild mit Rechtsklick abspeichere (mit Safari) erhalte ein cover.php.png. Du musst die Datei dann nur umbenennen.

Mit Chrome erhalte ich auf die selbe weise cover.php (also ohne .png Endung), umbenannt in cover.png ist das aber auch ein PNG wie es sein soll…

1 „Gefällt mir“

Hallo LeffSpike
Vielen Dank für das Skript - ich habe es für meine Bedürfnisse angepasst. Die Etiketten werden mit dem Ubuntu „glabels“ Label Designer ausgegeben. Dafür schreibe ich auch noch eine Log Datei in list_labels.csv, die dann von glabels zur Stapelverarbeitung eingelesen wird. Hier werden schwarz weiß Etiketten 50x83mm quer in 96dpi Bildern vorbereitet. So kann man 100 Etiketten in 40s gestalten, das Ausdrucken dauert dann etwas länger.

#!/bin/bash
#**************************************************************************
#   Copyright (C) 2024, Andreas Mascheck                                        *
#                                                                         *
#   This program is free software; you can redistribute it and/or modify  *
#   it under the terms of the GNU General Public License as published by  *
#   the Free Software Foundation; either version 2 of the License, or     *
#   (at your option) any later version.                                   *
#                                                                         *
#   This program is distributed in the hope that it will be useful,       *
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
#   GNU General Public License for more details.                          *
#                                                                         *
#   You should have received a copy of the GNU General Public License     *
#   along with this program; if not, write to the                         *
#   Free Software Foundation, Inc.,                                       *
#   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
#**************************************************************************
start=`date +%s`
# Configuration
#
# Images inside mp3 should be larger than 150 pixels wide, with a maximum size of 4MB
# our destination is 50x50mm with 600dpi the picture would have about 1200x1200pixel
# but PDF pictures have normally 96dpi this leads to 192x192 pixel
# These values match Herma No. 5028 has 50,8mm x 83,8mm giving a ratio of 1.649606299.
# ==> 2x3.3inches ==> 192x316pix
declare -i dstX=316
declare -i dstY=192
blurXY=0x2 #Blurring to be changed if size XY changes
#
#pointsize of font
declare -i tt1=10
declare -i tt2=14
declare -i tt3=25
#
#position of text
declare -i x0=($tt2*4) #number
declare -i x1=($tt2*2) #text left
declare -i x2=($dstX/2-$tt2) #mid
declare -i x3=($dstX-$tt2-$tt1) #right
declare -i y1=($dstY-$tt1/2)
declare -i y2=($y1-$tt1)
declare -i y3=($dstY/2)
#echo "$dstX , $x1 , $x2 , $x3"
#echo "$dstY , $y1 , $y2 , $y3"
myfont=Gillius-ADF-No2-Bold-Cond-Italic
# Temorary file for background
background=covermakerBackground.jpg
file=albumcover.jpg
#================= no parameters below ==================
#
if [ $# -ne 1 ] ; then
  echo "use as followes: bash covermakerB.sh /your_working_path/"
  echo " Example >>bash covermakerB.sh ./"
  exit 1
fi
if [ $1 == "-h" ] || [ $1 == "--help" ] ; then
  echo "=================== H E L P ================================"
  echo "This shell routine searches in all directories"
  echo "                          starting from your working path"
  echo "any first MP3 file and try to read the cover, the album "
  echo "and the artist. Finally it makes a black and white lable of"
  echo "316x192 pixel (83x50mm in 96dpi) out of those informations"
  echo "use as followes: bash covermakerB.sh /your_working_path/"
  echo " Example >>bash covermakerB.sh /media/my/tonuinoSD"
  echo "Needs imagemagick package for image manipulation!"
  echo "Writes and overwrites all DIR_label.jpg and list_label.csv"
  echo "============================================================"
  exit 0
fi
if [ ! -d $1 ] ; then
  echo "Error: path '$1' not valid "
  echo " Example >>bash covermakerB.sh ./"
  exit 1
fi
if [ $1 == "/" ] ; then
  echo "Error: path '$1' is to short"
  echo " Example >>bash covermakerB.sh ./"
  exit 1
fi
#====================================================================
#Start searching DIR with MP3
cd $1
# write a list for using in glabels Label Designer
echo "Filename;Source" > list_label.csv
#
shopt -s nullglob dotglob
unset -v name
#
for dir in $(find ./ -type d | sort) ; do # loop through directories
  for name in $dir/*.mp3 ; do
    [ -f "$name" ] && break
    unset -v name
  done
  #here we have one *.mp3 full qualified name or nothing
  if [ -v name ]; then
    mypath=$(dirname $name)
    myfile=$(basename $name)
    #
    artist=$(ffprobe $name -show_format 2>/dev/null | \
    awk -F"=" '$1 == "TAG:artist" {print $2}' | sed 's/\(.\{27\}\).*/\1.../')
    if [ -z "$artist" ]; then artist="." ; fi
    artist=$(echo "$artist" | awk '{gsub("\047", " "); print}')
    #
    album=$(ffprobe $name -show_format 2>/dev/null | \
    awk -F"=" '$1 == "TAG:album" {print $2}' |sed 's/\(.\{27\}\).*/\1.../')
    if [ -z "$album" ]; then album="." ; fi
    album=$(echo "$album" | awk '{gsub("\047", " "); print}')
    #
    mynummer=$(basename $mypath)
    if [ -z "$mynummer" ]; then mynummer="999999999" ; fi
    echo -e  "\n\n\n...$mynummer..."
    echo "============================="
    echo -e "doing \n      $artist $album"
    #
    # extract coverfile
    ffmpeg -y -i $name -an -c:v copy $file 2>/dev/null
    # check if coverfile exists
    if [ ! -f "$file" ]; then
      echo "no cover in mp3 file"
      nocover=1
      # create a white squared coverfile
      convert -size "$((dstY))x$((dstY))!" canvas:white "$file"
      #read -p "Continue? (Y/N): " \
      #confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
    else
      nocover=0
    fi
    outputFile="${mynummer}_label.jpg"
    #
    # Do the graphical work
    if [ $nocover == 0 ]; then
      # get it to desired size
      convert "$file" -resize "$((dstY))x$((dstY))!"  "$file"
      # make a pencil drawing from original - please install imagemagick
      convert "$file" -colorspace gray \
      \( +clone -blur "$blurXY" \) +swap -compose divide -composite \
      -linear-stretch 5%x0%   "$file"
    fi
    #
    # create a background
    convert -size "$((dstX))x$((dstY))!" canvas:white "$background"
    # and print the directory on it
    magick "$background" -font "$myfont" -pointsize "$tt1" \
    -fill black  -draw \
    "translate '$x0','$y1' rotate -90 text 0,0 '$mynummer'" \
    "$background"
    # write artist
    magick "$background" -font "$myfont" -pointsize "$tt2" \
    -fill black  -draw \
    "translate '$x1','$y2' rotate -90 text 0,0 '$artist'" \
    "$background"
    # write album
    magick "$background" -font "$myfont" -pointsize "$tt2" \
    -fill black  -draw \
    "translate '$x3','$y2' rotate -90 text 0,0 '$album'" \
    "$background"
    # Put the original image in the middle of the background and be done
    if [ $nocover == 0 ]; then
      convert "$background" "$file" \
      -gravity center -composite \
      -flatten \
      "$outputFile"
    else
      magick "$background" -pointsize "$tt3" \
      -fill black -draw "translate '$x2','$y3' text 0,0 '$mynummer" \
      "$outputFile"
    fi
    # Clean up
    #
    echo "$(pwd)/$outputFile;$name" >> list_label.csv
    #uncomment for imagemagick preview
    #display -delay 1 "$outputFile" #display command from imagemagick
    # Delete temporary file
    rm "$file"
    rm "$background"
  fi
  unset -v name
done # loop of directories
end=`date +%s`
echo " worked: $((end-start)) seconds "
echo -e "         outputfiles are named in \n$(pwd)/list_label.csv"