Created
September 4, 2025 18:13
-
-
Save aderumier/5d670c6f85a26c8881c6896b4cb562ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # Script ImageMagick avancé pour créer une couverture de jeu | |
| # Usage: ./create_advanced_game_cover.sh [options] titlescreen gameplay logo output | |
| # Paramètres par défaut | |
| WIDTH=600 | |
| HEIGHT=800 | |
| LOGO_POSITION="north" | |
| LOGO_OFFSET="+0+60" | |
| GRADIENT_HEIGHT=400 | |
| BORDER_SIZE=2 | |
| BORDER_COLOR="#333333" | |
| BLUR_BACKGROUND=false | |
| VINTAGE_EFFECT=false | |
| USE_BLURRED_BG=true | |
| BLUR_INTENSITY=30 | |
| BACKGROUND_COLOR="black" | |
| SECONDARY_LOGO="" | |
| SECONDARY_POSITION="north" | |
| TITLE_BORDER_SIZE=3 | |
| TITLE_BORDER_COLOR="black" | |
| # Fonction d'aide | |
| show_help() { | |
| cat << EOF | |
| Usage: $0 [OPTIONS] <titlescreen> <logo> <output> | |
| OPTIONS: | |
| -w, --width WIDTH Largeur de la couverture (défaut: 600) | |
| -h, --height HEIGHT Hauteur de la couverture (défaut: 800) | |
| -p, --position POS Position du logo: north, south, center (défaut: north) | |
| -o, --offset OFFSET Décalage du logo (défaut: +0+60) | |
| -g, --gradient HEIGHT Hauteur du dégradé (défaut: 200) | |
| --bg-blur INTENSITY Intensité du flou pour le background (défaut: 20) | |
| --no-bg-blur Utiliser une couleur unie au lieu du background flouté | |
| --border SIZE Taille de la bordure (défaut: 2) | |
| --border-color COLOR Couleur de la bordure (défaut: #333333) | |
| -b, --background COLOR Couleur de fond si --no-bg-blur est utilisé (défaut: black) | |
| --blur Appliquer un flou léger au background | |
| --vintage Appliquer un effet vintage | |
| --secondary-logo FILE Logo secondaire (optionnel) | |
| --secondary-pos POS Position du logo secondaire (défaut: north) | |
| --secondary-offset OFF Offset du logo secondaire (défaut: +0+30) | |
| --title-border SIZE Taille du cadre autour de l'image title (défaut: 3) | |
| --title-border-color COL Couleur du cadre de l'image title (défaut: black) | |
| --help Afficher cette aide | |
| EXEMPLES: | |
| $0 title.jpg gameplay.jpg logo.png cover.jpg | |
| $0 --bg-blur 30 --vintage title.jpg gameplay.jpg logo.png cover.jpg | |
| $0 --secondary-logo mame.png --secondary-pos north title.jpg gameplay.jpg logo.png cover.jpg | |
| $0 --no-bg-blur --background white --position center title.jpg gameplay.jpg logo.png cover.jpg | |
| EOF | |
| } | |
| # Fonction de validation des dépendances | |
| validate_dependencies() { | |
| if ! command -v convert >/dev/null 2>&1; then | |
| echo "Erreur: ImageMagick n'est pas installé ou 'convert' n'est pas dans le PATH" | |
| echo "Installation:" | |
| echo " Ubuntu/Debian: sudo apt install imagemagick" | |
| echo " CentOS/RHEL: sudo yum install ImageMagick" | |
| echo " macOS: brew install imagemagick" | |
| exit 1 | |
| fi | |
| if ! command -v identify >/dev/null 2>&1; then | |
| echo "Avertissement: 'identify' n'est pas disponible, les informations finales ne seront pas affichées" | |
| fi | |
| } | |
| # Fonction de validation des paramètres numériques | |
| validate_numeric() { | |
| local value="$1" | |
| local param_name="$2" | |
| if ! [[ "$value" =~ ^[0-9]+$ ]]; then | |
| echo "Erreur: $param_name doit être un nombre entier positif (reçu: '$value')" | |
| exit 1 | |
| fi | |
| } | |
| # Fonction de traitement des logos | |
| process_logo() { | |
| local logo_file="$1" | |
| local max_width="$2" | |
| local max_height="$3" | |
| local temp_output="$4" | |
| echo " Traitement du logo: $logo_file" | |
| convert "$logo_file" \ | |
| -resize "${max_width}x${max_height}>" \ | |
| -background transparent \ | |
| "$temp_output" | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors du traitement du logo: $logo_file" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| } | |
| # Fonction de composition des logos | |
| compose_logo() { | |
| local input_image="$1" | |
| local logo_file="$2" | |
| local position="$3" | |
| local offset="$4" | |
| local output_image="$5" | |
| echo " Composition du logo en position: $position" | |
| convert "$input_image" \ | |
| "$logo_file" \ | |
| -gravity "$position" \ | |
| -geometry "$offset" \ | |
| -composite \ | |
| "$output_image" | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors de la composition du logo" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| } | |
| # Fonction de nettoyage des fichiers temporaires | |
| cleanup_temp_files() { | |
| echo "Nettoyage des fichiers temporaires..." | |
| rm -f temp_bg.jpg temp_with_gradient.jpg temp_logo.png temp_secondary_logo.png \ | |
| temp_final.jpg temp_blurred_bg.jpg temp_main.jpg temp_final_with_secondary.jpg | |
| } | |
| # Parsing des arguments | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| -w|--width) | |
| WIDTH="$2" | |
| validate_numeric "$WIDTH" "width" | |
| shift 2 | |
| ;; | |
| -h|--height) | |
| HEIGHT="$2" | |
| validate_numeric "$HEIGHT" "height" | |
| shift 2 | |
| ;; | |
| -p|--position) | |
| if [[ ! "$2" =~ ^(north|south|center)$ ]]; then | |
| echo "Erreur: Position doit être 'north', 'south' ou 'center'" | |
| exit 1 | |
| fi | |
| LOGO_POSITION="$2" | |
| shift 2 | |
| ;; | |
| -o|--offset) | |
| LOGO_OFFSET="$2" | |
| shift 2 | |
| ;; | |
| -g|--gradient) | |
| GRADIENT_HEIGHT="$2" | |
| validate_numeric "$GRADIENT_HEIGHT" "gradient height" | |
| shift 2 | |
| ;; | |
| --bg-blur) | |
| BLUR_INTENSITY="$2" | |
| validate_numeric "$BLUR_INTENSITY" "blur intensity" | |
| shift 2 | |
| ;; | |
| --no-bg-blur) | |
| USE_BLURRED_BG=false | |
| shift | |
| ;; | |
| -b|--background) | |
| BACKGROUND_COLOR="$2" | |
| USE_BLURRED_BG=false | |
| shift 2 | |
| ;; | |
| --border) | |
| BORDER_SIZE="$2" | |
| validate_numeric "$BORDER_SIZE" "border size" | |
| shift 2 | |
| ;; | |
| --border-color) | |
| BORDER_COLOR="$2" | |
| shift 2 | |
| ;; | |
| --blur) | |
| BLUR_BACKGROUND=true | |
| shift | |
| ;; | |
| --vintage) | |
| VINTAGE_EFFECT=true | |
| shift | |
| ;; | |
| --secondary-logo) | |
| SECONDARY_LOGO="$2" | |
| shift 2 | |
| ;; | |
| --secondary-pos) | |
| if [[ ! "$2" =~ ^(north|south|center)$ ]]; then | |
| echo "Erreur: Position secondaire doit être 'north', 'south' ou 'center'" | |
| exit 1 | |
| fi | |
| SECONDARY_POSITION="$2" | |
| shift 2 | |
| ;; | |
| --secondary-offset) | |
| SECONDARY_OFFSET="$2" | |
| shift 2 | |
| ;; | |
| --title-border) | |
| TITLE_BORDER_SIZE="$2" | |
| validate_numeric "$TITLE_BORDER_SIZE" "title border size" | |
| shift 2 | |
| ;; | |
| --title-border-color) | |
| TITLE_BORDER_COLOR="$2" | |
| shift 2 | |
| ;; | |
| --help) | |
| show_help | |
| exit 0 | |
| ;; | |
| -*) | |
| echo "Option inconnue: $1" | |
| show_help | |
| exit 1 | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| done | |
| # Validation des dépendances | |
| validate_dependencies | |
| # Vérification des arguments restants | |
| if [ $# -ne 4 ]; then | |
| echo "Erreur: Vous devez spécifier titlescreen, gameplay, logo et fichier de sortie" | |
| show_help | |
| exit 1 | |
| fi | |
| TITLESCREEN="$1" | |
| GAMEPLAY="$2" | |
| LOGO="$3" | |
| OUTPUT="$4" | |
| # Vérification des fichiers d'entrée | |
| if [ ! -f "$TITLESCREEN" ]; then | |
| echo "Erreur: Le fichier titlescreen '$TITLESCREEN' n'existe pas" | |
| exit 1 | |
| fi | |
| if [ ! -f "$GAMEPLAY" ]; then | |
| echo "Erreur: Le fichier gameplay '$GAMEPLAY' n'existe pas" | |
| exit 1 | |
| fi | |
| if [ ! -f "$LOGO" ]; then | |
| echo "Erreur: Le fichier logo '$LOGO' n'existe pas" | |
| exit 1 | |
| fi | |
| if [ -n "$SECONDARY_LOGO" ] && [ ! -f "$SECONDARY_LOGO" ]; then | |
| echo "Erreur: Le fichier logo secondaire '$SECONDARY_LOGO' n'existe pas" | |
| exit 1 | |
| fi | |
| # Vérification des conflits de position | |
| if [ -n "$SECONDARY_LOGO" ] && [ "$LOGO_POSITION" = "$SECONDARY_POSITION" ]; then | |
| echo "Avertissement: Les deux logos sont à la même position ($LOGO_POSITION), ils peuvent se chevaucher" | |
| fi | |
| echo "=== CRÉATION DE LA COUVERTURE DE JEU ===" | |
| echo "Titlescreen (background): $TITLESCREEN" | |
| echo "Gameplay (image principale): $GAMEPLAY" | |
| echo "Logo principal: $LOGO (position: $LOGO_POSITION)" | |
| if [ -n "$SECONDARY_LOGO" ]; then | |
| echo "Logo secondaire: $SECONDARY_LOGO (position: $SECONDARY_POSITION)" | |
| fi | |
| echo "Sortie: $OUTPUT" | |
| echo "Dimensions: ${WIDTH}x${HEIGHT}" | |
| echo "Image gameplay: ${GAMEPLAY_WIDTH}px largeur max, centré dans les 2/3 inférieurs, cadre ${TITLE_BORDER_COLOR} ${TITLE_BORDER_SIZE}px" | |
| echo "Background flouté: $USE_BLURRED_BG" | |
| if [ "$USE_BLURRED_BG" = true ]; then | |
| echo "Intensité flou: $BLUR_INTENSITY" | |
| fi | |
| echo "Effets: Blur=$BLUR_BACKGROUND, Vintage=$VINTAGE_EFFECT" | |
| echo | |
| # Étape 1: Créer le background flouté ou préparer l'image principale | |
| echo "1. Préparation du background..." | |
| # Calculer les dimensions pour l'image gameplay (75% de largeur) | |
| GAMEPLAY_WIDTH=$((WIDTH * 75 / 100)) | |
| if [ "$USE_BLURRED_BG" = true ]; then | |
| # Créer un background flouté à partir du titlescreen | |
| convert "$TITLESCREEN" \ | |
| -resize "${WIDTH}x${HEIGHT}^" \ | |
| -gravity center \ | |
| -extent "${WIDTH}x${HEIGHT}" \ | |
| -blur "0x${BLUR_INTENSITY}" \ | |
| temp_blurred_bg.jpg | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors de la création du background flouté" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| # Préparer l'image gameplay à 75% de largeur avec cadre noir | |
| convert "$GAMEPLAY" \ | |
| -resize "${GAMEPLAY_WIDTH}x${HEIGHT}>" \ | |
| -bordercolor "$TITLE_BORDER_COLOR" \ | |
| -border "${TITLE_BORDER_SIZE}x${TITLE_BORDER_SIZE}" \ | |
| temp_main.jpg | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors du redimensionnement de l'image gameplay" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| # Composer l'image gameplay sur le background flouté (titlescreen) | |
| # Centrer dans les 2/3 inférieurs de l'image | |
| GAMEPLAY_Y_OFFSET=$((HEIGHT / 6)) # Décalage vers le bas (1/6 de hauteur) | |
| convert temp_blurred_bg.jpg temp_main.jpg -gravity center -geometry "+0+${GAMEPLAY_Y_OFFSET}" -composite temp_bg.jpg | |
| else | |
| # Mode original avec couleur de fond - image gameplay à 75% de largeur avec cadre | |
| # Centrer dans les 2/3 inférieurs | |
| GAMEPLAY_Y_OFFSET=$((HEIGHT / 6)) | |
| convert "$GAMEPLAY" \ | |
| -resize "${GAMEPLAY_WIDTH}x${HEIGHT}>" \ | |
| -bordercolor "$TITLE_BORDER_COLOR" \ | |
| -border "${TITLE_BORDER_SIZE}x${TITLE_BORDER_SIZE}" \ | |
| temp_main.jpg | |
| # Créer le fond avec l'image gameplay positionnée dans les 2/3 inférieurs | |
| convert -size "${WIDTH}x${HEIGHT}" xc:"$BACKGROUND_COLOR" \ | |
| temp_main.jpg \ | |
| -gravity center \ | |
| -geometry "+0+${GAMEPLAY_Y_OFFSET}" \ | |
| -composite temp_bg.jpg | |
| fi | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors de la préparation du background" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| # Ajouter flou si demandé (pour l'image principale uniquement) | |
| if [ "$BLUR_BACKGROUND" = true ]; then | |
| echo " Application du flou léger..." | |
| convert temp_bg.jpg -blur 0x2 temp_bg.jpg | |
| fi | |
| # Étape 2: Appliquer effet vintage si demandé | |
| if [ "$VINTAGE_EFFECT" = true ]; then | |
| echo "2. Application de l'effet vintage..." | |
| convert temp_bg.jpg \ | |
| -modulate 110,130,100 \ | |
| -colorize 10,5,0 \ | |
| -sigmoidal-contrast 2,50% \ | |
| temp_bg.jpg | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors de l'application de l'effet vintage" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| fi | |
| # Étape 3: Ajouter dégradé selon position du logo | |
| echo "3. Ajout du dégradé..." | |
| case $LOGO_POSITION in | |
| "north") | |
| convert temp_bg.jpg \ | |
| \( -size "${WIDTH}x${GRADIENT_HEIGHT}" gradient:black-transparent \) \ | |
| -gravity north \ | |
| -composite temp_with_gradient.jpg | |
| ;; | |
| "south") | |
| convert temp_bg.jpg \ | |
| \( -size "${WIDTH}x${GRADIENT_HEIGHT}" gradient:transparent-black \) \ | |
| -gravity south \ | |
| -composite temp_with_gradient.jpg | |
| ;; | |
| "center") | |
| convert temp_bg.jpg \ | |
| \( -size "${WIDTH}x$((HEIGHT/3))" gradient:transparent-black \) \ | |
| -gravity center \ | |
| -composite temp_with_gradient.jpg | |
| ;; | |
| *) | |
| cp temp_bg.jpg temp_with_gradient.jpg | |
| ;; | |
| esac | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors de l'ajout du dégradé" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| # Étape 4: Traitement des logos | |
| echo "4. Préparation des logos..." | |
| LOGO_MAX_WIDTH=$((WIDTH * 80 / 100)) | |
| LOGO_MAX_HEIGHT=$((HEIGHT * 25 / 100)) | |
| # Traitement du logo principal | |
| process_logo "$LOGO" "$LOGO_MAX_WIDTH" "$LOGO_MAX_HEIGHT" "temp_logo.png" | |
| # Traitement du logo secondaire si spécifié | |
| if [ -n "$SECONDARY_LOGO" ]; then | |
| process_logo "$SECONDARY_LOGO" "$LOGO_MAX_WIDTH" "$LOGO_MAX_HEIGHT" "temp_secondary_logo.png" | |
| fi | |
| # Étape 5: Composition finale | |
| echo "5. Composition finale..." | |
| # Composer le logo principal | |
| compose_logo "temp_with_gradient.jpg" "temp_logo.png" "$LOGO_POSITION" "$LOGO_OFFSET" "temp_final.jpg" | |
| # Composer le logo secondaire si présent | |
| if [ -n "$SECONDARY_LOGO" ]; then | |
| compose_logo "temp_final.jpg" "temp_secondary_logo.png" "$SECONDARY_POSITION" "$SECONDARY_OFFSET" "temp_final_with_secondary.jpg" | |
| FINAL_TEMP="temp_final_with_secondary.jpg" | |
| else | |
| FINAL_TEMP="temp_final.jpg" | |
| fi | |
| # Étape 6: Ajouter bordure si demandée | |
| if [ "$BORDER_SIZE" -gt 0 ]; then | |
| echo "6. Ajout de la bordure..." | |
| convert "$FINAL_TEMP" \ | |
| -bordercolor "$BORDER_COLOR" \ | |
| -border "${BORDER_SIZE}x${BORDER_SIZE}" \ | |
| "$OUTPUT" | |
| if [ $? -ne 0 ]; then | |
| echo "Erreur lors de l'ajout de la bordure" | |
| cleanup_temp_files | |
| exit 1 | |
| fi | |
| else | |
| cp "$FINAL_TEMP" "$OUTPUT" | |
| fi | |
| # Nettoyage | |
| cleanup_temp_files | |
| echo | |
| echo "✅ Couverture créée avec succès: $OUTPUT" | |
| # Informations sur le fichier final | |
| if command -v identify &> /dev/null; then | |
| echo | |
| echo "Informations du fichier:" | |
| identify "$OUTPUT" | |
| if command -v du &> /dev/null; then | |
| echo "Taille du fichier: $(du -h "$OUTPUT" | cut -f1)" | |
| fi | |
| fi | |
| echo | |
| echo "Fini ! Votre couverture de jeu est prête à l'emploi." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment