[SI-LINDER-PARTNER-6][OSC] - Révision du canal alpha du gestionnaire de traitement par lots des filigranes des images (produits, catégories) /* Les commentaires de codes PHP (hors de cette zone de commentaires), sont en Anglais afin de respecter l'ancien nommage de ce script de filigrane L'image de filigrane utilisée (la surcouche) a subit une modification, en 2021, son opacité a été réduit de 100% à 20% De manière à éviter le filigrane trop visible. A noter, les images DÉJÀ filigranées, seront soumises à un traitement spécial: - Par défaut un commentaire (metadata: "comment") était ajouté aux images JAMAIS traitées par le filigrane. - Le commentaire ajouté était sous la forme de: LinderPartner - 2.0 - Ce commentaire permettait une fois ajouté aux metatags des images un mécanisme de détection/vérification/échappement: - si lors d'un traitement par lots futur, le filigranateur (create_watermark.php) devait traiter ces images de nouveaux.. - il vérifierait au préalable si la chaîne de commentaire metadata "comment" avec pour contenu: "LinderPartner - " existait ou pas: - si oui: on ne retraitait pas l'image - si non: on traitait l'image (ajout du filigrane au-dessus de l'image). - Le système de filigrane est géré par IMagick, (et PHP) donc, sans IMagick, ce système de filigrane ne fonctionnerait pas - Car seul IMagick gère les commentaires META des images... - IMagick gère les commentaires META uniquement dans les fichiers .jpg/.jpeg apparemment (à vérifier sur une nouvelle version de IMagick, d'une manière ou d'une autre?) - Et bien, en 2021, on a modifié ce comportement en deux étapes 1/ On va éditer avec un logiciel graphique (ici the GIMP) l'image utilisée en tant que filigrane, pour en réduire son opacité jusqu'à 20% max. 2/ On va modifier la chaîne de commentaire ajoutée pour "quand même" retraiter les images déjà traitées: "ce comportement va juste augmenter de 10% l'opacité de l'ancienne version filigranée des images) - En spécifiant alors "SI LinderPartner" 3/ On va modifier la recherche du commentaire - En cherchant alors "SI LinderPartner - " OU "LinderPartner - " Est présent, si oui, on ne fait rien (car déjà filigranée: already processed), si non, on filigrane 4/ On modifie ici le commentaire, il était incorrect face à la fonctionnalité véritablement représentée 5/ On modifie un peu le formatage de la ligne de debug, histoire d'aérer un peu ça... */ // watermark // [1] // notes: (in 2021, the image used as watermark layer was reduced from opacity 100% to 20%) $WATERMARK_FILE = $HERE . "/images/image/logo/lp_filigrane_gris_1.png"; // when set to 1, no images are processed (debug mode) $SIMULATE = 0; // [4] // notes: (when set to 0, no debug output (debug mode)) $VERBOSE = 1; // meta data comment to be added // [2] // notes: (in 2021, edited to) $VERSION = "SI LinderPartner - 4.0"; // filenames repositories for reports $ALL_OK_PROCESSED = array(); $ALL_OK_ALREADY_PROCESSED = array(); $ALL_ERR = array(); // echo verbose function echo_info($txt) { global $VERBOSE; // [5] // notes: (we update a little the debug output in 2021) if ( $VERBOSE == 1 ) { echo '
  @  ' . $txt . '
'; } } // process a single directory function process_directory($dirname) { global $SIMULATE; if ( $SIMULATE == 1 ) { echo "Processing directory $dirname\n"; } if ($handle = opendir($dirname)) { while (false !== ($entry = readdir($handle))) { $filename = $dirname . '/' . $entry; if ( is_file($filename) ) { $path_parts = pathinfo($filename); if ( strcasecmp($path_parts['extension'], 'jpg') == 0 || strcasecmp($path_parts['extension'], 'jpeg') == 0 || strcasecmp($path_parts['extension'], 'gif') == 0 || strcasecmp($path_parts['extension'], 'bmp') == 0 || strcasecmp($path_parts['extension'], 'png') == 0 ) { process_image($filename); } } elseif ( is_dir($filename) && $entry !== "." && $entry !== ".." && $entry !== "logo" ) { process_directory($filename); } } closedir($handle); } } // process a single image file function process_image($filename) { global $SIMULATE; global $BACKUP_DIR; global $VERSION; global $ALL_OK_PROCESSED; global $ALL_OK_ALREADY_PROCESSED; global $ALL_ERR; global $WATERMARK_FILE; if ( $SIMULATE == 1 ) { echo "$filename ...\n"; return; } try { $image = new Imagick(); $image->readImage($filename); // [5]-->[SI-LINDER-PARTNER-6][OSC]::BEGIN // notes: (we update a little the debug output in 2021) echo_info(" # $filename - comment property = <" . $image->getImageProperty("comment") . ">" . "\n"); // [5]-->[SI-LINDER-PARTNER-6][OSC]::END // [5]-->[SI-LINDER-PARTNER-6][OSC]::BEGIN // notes: (in 2021, edition for new meta data (we edit the metatag data comment for the image if jpg/jpeg), // (need it in order to do not watermarking twice an image which possess the NEW watermark V3.0) if ( ( strstr($image->getImageProperty("comment"), 'SI LinderPartner - ') or strstr($image->getImageProperty("comment"), 'LinderPartner - ') === FALSE ) ) // [5]-->[SI-LINDER-PARTNER-6][OSC]::END { // file has not been processed yet, let's continue $backup_filename = $BACKUP_DIR . '/' . $filename; $backup_dirname = dirname($backup_filename); if ( !is_dir($backup_dirname) ) { mkdir($backup_dirname, 0755, true); } if ( is_file($backup_filename) ) { // [5]-->[SI-LINDER-PARTNER-6][OSC]::BEGIN // notes: (we update a little the debug output in 2021 and avoid non-ascii characters) echo_info(" ~ $filename - backup $backup_filename already exists, nothing to do\n"); $ALL_ERR["$filename"] = " ~ fichier déjà présent dans la zone de sauvegarde\n\n"; // [5]-->[SI-LINDER-PARTNER-6][OSC]::END } else if ( copy($filename, $backup_filename) ) // ensure we can make a backup before working on the image { $watermark = new Imagick(); $watermark->readImage($WATERMARK_FILE); if ( $image->getNumberImages() > 1 ) // animated gif ? { // need to split images into frames to get the proper width/height $image = $image->coalesceImages(); } // how big are the images? $iWidth = $image->getImageWidth(); $iHeight = $image->getImageHeight(); // resize the watermark if ( $iHeight < $iWidth ) { $wSize = $iHeight * 0.75; } else { $wSize = $iWidth * 0.75; } $watermark->scaleImage($wSize, $wSize); $watermark->evaluateImage(Imagick::EVALUATE_DIVIDE, 2, Imagick::CHANNEL_ALPHA); // get new size $wWidth = $watermark->getImageWidth(); $wHeight = $watermark->getImageHeight(); // calculate the position $x = ($iWidth - $wWidth)/2; $y = ($iHeight - $wHeight)/2; // add copyright as meta data (not supported by .gif, .bmp, and ... ?) $image->commentImage($VERSION); if ( $image->getNumberImages() > 1 ) // animated gif ? { // draw watermark on all frames foreach ($image as $frame) { $frame->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y); } $image->optimizeImageLayers(); $image = $image->deconstructImages(); $image->writeImages($filename, true); } else { // draw watermark $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y); $image->writeImage($filename); } $image->clear(); $image->destroy(); $ALL_OK_PROCESSED["$filename"] = 1; // [5]-->[SI-LINDER-PARTNER-6][OSC]::BEGIN // notes: (we update a little the debug output in 2021 and avoid non-ascii characters) echo_info(" + $filename - PROCESSED\n\n"); // [5]-->[SI-LINDER-PARTNER-6][OSC]::END } else { // [5]-->[SI-LINDER-PARTNER-6][OSC]::BEGIN // notes: (we update a little the debug output in 2021 and avoid non-ascii characters) echo_info(" ! $filename - cannot copy backup $backup_filename\n"); $ALL_ERR['$filename'] = " ! fichier sans logo mais déjà présent dans la zone de sauvegarde\n\n"; // [5]-->[SI-LINDER-PARTNER-6][OSC]::END } } else { // [5]-->BEGIN[SI-LINDER-PARTNER-6][OSC]::END // notes: (we update a little the debug output in 2021 and avoid non-ascii characters) echo_info(" - $filename - already PROCESSED, nothing to do\n\n"); $ALL_OK_ALREADY_PROCESSED["$filename"] = 1; } } catch(ImagickException $e) { echo "$filename - exception" . $e->getMessage() . "\n"; $ALL_ERR["$filename"] = " |> erreur de format de fichier : " . $e->getMessage(); } } // process main directory process_directory($IMAGE_DIR); // generate report ... // ([5])-->BEGIN[SI-LINDER-PARTNER-6][OSC]::END // notes: (add linejumps to aerate the following output and avoid non-ascii characters) echo "
\nNouveaux fichiers traités : " . strval(sizeof($ALL_OK_PROCESSED)) . "\n
"; // ([5])-->[SI-LINDER-PARTNER-6][OSC]::BEGIN // notes: (textarea to contain all the processed files with state OK) echo ''; // ([5])-->[SI-LINDER-PARTNER-6][OSC]::END // ([5])-->BEGIN[SI-LINDER-PARTNER-6][OSC]::END // notes: (add linejumps to aerate the following output and avoid non-ascii characters) echo "
\nFichiers déja traités : " . strval(sizeof($ALL_OK_ALREADY_PROCESSED)) . "\n
"; // ([5])-->BEGIN[SI-LINDER-PARTNER-6][OSC]::END // notes: (add linejumps to aerate the following output and avoid non-ascii characters) echo "
\nErreurs : " . strval(sizeof($ALL_ERR)) . "\n
"; foreach ( $ALL_ERR as $filename => $txt ) { // ([5])-->BEGIN[SI-LINDER-PARTNER-6][OSC]::END // notes: (add linejump to aerate the following output and avoid non-ascii characters) echo "
\n - $filename : " . $txt . "\n";
}
// <- [SI-LINDER-PARTNER-6][OSC] - Révision du canal alpha du gestionnaire de traitement par lots des filigranes des images (produits, catégories)
?>