Bonjour,
Filigrane de (C) permanent avec GD2 (par Sammy, modif par Burpee)
Traduction du mode concernant le filigranage des photos. en trois parties.
Pour utilisateurs relativement expérimentés et qui désirent ajouter la fonction du filigrane GD2 sur leur galerie.
'Seulement' 10 minutes environ pour ajouter cette modification.
UTILISE GD2 et SAFE MODE !
Comment modifier CPG 1.3 et ajouter un filigrane sur la nouvelle image et par choix sur toutes les images dans l'album choisi.
Dossiers qui doivent être modifiés :
Lang/french.php
incluent/picmgmt.inc.php
util.php
config.php
(et 4 commandes de SQL pour l'exécution)
Sauvez tous les fichiers d'origine que vous modifiez !
1. Ouvrir le dossier Lang/french.php
Trouver ceci :
Code:
'th_wd' => 'Largeur',
Ajouter ceci après cette ligne,
Code:
'wm_bottomright' => 'En bas à droite',
'wm_bottomleft' => 'En bas à gauche',
'wm_topleftt' => 'En haut à gauche',
'wm_topright' => 'En haut à droite',
'wm_both' => 'Les deux',
'wm_original' => 'Original',
'wm_resized' => 'Retaillé',
Trouver ceci:
Code:
array('Display notices in debug mode', 'debug_notice', 1), //cpg1.3.0
Ajouter ceci après la dernière ligne ,
Code:
'Image watermarking',
array('Watermark Image en Upload', 'enable_watermark', 1),
array('Où placer le Watermark', 'where_put_watermark', 11),
array('Quels fichiers à marquer', 'which_files_to_watermark', 12),
array('Quel fichier image utiliser pour le watermark', 'watermark_file', 0),
trouver cette ligne;
Code:
'delete_orphans' => 'Effacer les commentaires orphelins (fonctionne sur tous les albums)', (ou quelque chose dans ce genre en fonction de votre fichier french.php)
ajouter ceci après cette ligne;
Code:
'watermarks' => 'Ajoutez des Watermarks',
'watermark_normal' => 'Aux images aux dimensions modifiées uniquement',
'watermark_image' => 'Aux images dans leurs dimensions d'Origine',
'watermark_both' => 'Aux images Originales et celles redimensionnées',
'watermark_wait' => 'PROCESS Watermarkage des images en cours...',
'watermark_continue_wait' => 'Poursuite du Watermarkage des images originales et/ou des retaillées...',
2. ouvrez le fichier include/picmgmt.inc.php
trouvez cette ligne
Code:
$image_filesize = filesize($image);
Ajouter ceci devant elle
Code:
//Adds (c) to new images
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark']
== 'both' || $CONFIG['which_files_to_watermark'] == 'original') {
if (!watermark($image)) //this is for full size image
return false;
}
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] ==
'both' || $CONFIG['which_files_to_watermark'] == 'resized') {
if (file_exists($normal) && !watermark($normal)) //this is for intermediate size image
return false;
}
allez à la fin du fichier picmgnt.inc.php, et trouvez ceci;
Code:
?>
ajoutez avant cette ligne;
/**
* watermark_image()
*
* Create a file containing a watermarked image *
* @param $src_file the source file
* @param $dest_file the destination file
* @param $new_size the size of the square within which the new image must fit
* @param $method the method used for image resizing //ainoastaan gd2
* @return 'true' in case of success
*/
function watermark($src_file)
{
global $CONFIG, $ERROR;
global $lang_errors;
$imginfo = getimagesize($src_file);
if ($imginfo == null)
return false;
// GD ne peut manipuler que JPG & PNG
if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG) {
$ERROR = $lang_errors['gd_file_type_err'];
return false;
}
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
/* if ($thumb_use == 'ht') {
$ratio = $srcHeight / $new_size;
} elseif ($thumb_use == 'wd') {
$ratio = $srcWidth / $new_size;
} else
{
$ratio = max($srcWidth, $srcHeight) / $new_size;
}
$ratio = max($ratio, 1.0);*/
$destWidth = $srcWidth; //(int)($srcWidth / $ratio);
$destHeight = $srcHeight; //(int)($srcHeight / $ratio);
$dest_file = $src_file;
// Method for thumbnails creation
// switch ($method) {
// case "gd2" :
if (!function_exists('imagecreatefromjpeg')) {
cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD
image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__);
}
if (!function_exists('imagecreatetruecolor')) {
cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support GD
version 2.x, please switch to GD version 1.x on the config page', __FILE__, __LINE__);
}
if ($imginfo[2] == GIS_JPG)
$src_img = imagecreatefromjpeg($src_file);
else
$src_img = imagecreatefrompng($src_file);
if (!$src_img) {
$ERROR = $lang_errors['invalid_image'];
return false;
} // duunataan wesileima
$dst_img = imagecreatetruecolor($destWidth, $destHeight);
/*$dst_img =*/ ImageAlphaBlending($dst_img, true) or die ("Could
not alpha blend"); // Enable when on GD 2+
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int)$destHeight,
$srcWidth, $srcHeight);
$logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
//where is the watermark displayed...
$pos = $CONFIG['where_put_watermark'];
if ($pos == "topleft") {
$src_x = 5;
$src_y = 5;
} else if ($pos == "topright") {
$src_x = $srcWidth - ($logoW + 5);
$src_y = 5;
} else if ($pos == "bottomleft") {
$src_x = 5;
$src_y = $srcHeight - ($logoH + 5);
} else if ($pos == "bottomright") {
$src_x = $srcWidth - ($logoW + 5);
$src_y = $srcHeight - ($logoH + 5);
}
ImageCopy($dst_img,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH);
//$dst_x,$dst_y,0,0,$logoW,$logoH);
imagejpeg($dst_img, $src_file, $CONFIG['jpeg_qual']);
imagedestroy($src_img);
imagedestroy($dst_img);
// break;
//}
// Set mode of uploaded picture
// We check that the image is valid
$imginfo = getimagesize($src_file);
if ($imginfo == null) {
$ERROR = $lang_errors['resize_failed'];
@unlink($src_file);
return false;
} else {
return true;
}
}
3. ouvrez le fichier util.php (dans la racine de votre galerie)
trouvez cette ligne;
Code:
function deleteorig()
ajouter devant cette ligne;
Code:
function vesileimaathumbit() //watermarkthumbs
{
global $picturetbl, $CONFIG, $lang_util_php;
$phpself = $_SERVER['PHP_SELF'];
$albumid = $_POST['albumid'];
$updatetype = $_POST['updatetype'];
$numpics = $_POST['numpics'];
$startpic = 0;
$startpic = $_POST['startpic'];
$query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
$result = MYSQL_QUERY($query);
$totalpics = mysql_numrows($result);
if ($startpic == 0) {
// 0 - numpics
$num = $totalpics;
// Over picture limit
if ($totalpics > $numpics) $num = $startpic + $numpics;
} else {
// startpic - numpics
$num = $startpic + $numpics;
if ($num > $totalpics) $num = $totalpics;
}
$i = $startpic;
while ($i < $num) {
$image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result,
$i, "filename");
if ($updatetype == 0 || $updatetype == 2) {
$imagesize = getimagesize($image);
if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] &&
$CONFIG['make_intermediate']) {
$image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") .
$CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
} else {
$image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") .
mysql_result($result, $i, "filename");
}
if (watermark($image)) {
print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '.
$lang_util_php['updated_succesfully'] . '!<br />';
my_flush();
} else {
print $lang_util_php['error_create'] . ':$image<br />';
//$lang_util_php['error_create'] . ':$normal<br />';
my_flush();
}
}
if ($updatetype == 1 || $updatetype == 2) {
$image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") .
mysql_result($result, $i, "filename");
if (watermark($image)) {
print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '.
$lang_util_php['updated_succesfully'] . '!<br />';
my_flush();
} else {
print $lang_util_php['error_create'] . ':$image<br />';
//$lang_util_php['error_create'] . ':$normal<br />';
my_flush();
}
}
++$i;
}
$startpic = $i;
if ($startpic < $totalpics) {
?>
<form action=<?php echo $phpself;
?> method="post">
<input type="hidden" name="action" value="continuewatermarks" />
<input type="hidden" name="numpics" value="<?php echo $numpics?>" />
<input type="hidden" name="startpic" value="<?php echo $startpic?>" />
<input type="hidden" name="updatetype" value="<?php echo $updatetype?>" />
<input type="hidden" name="albumid" value="<?php echo $albumid?>" />
<input type="submit" value="<?php print $lang_util_php['continue'];
?>" class="submit" /></form>
<?php
}
}
trouver cette ligne;
Code:
updatethumbs();
ajoutez aprés cette ligne;
Code:
echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'watermarks') {//tämä
global $picturetbl, $CONFIG;
print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';
vesileimaathumbit(); //watermarkthumbs
echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'continuewatermarks') {//tämä
print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';
vesileimaathumbit(); //watermarkthumbs
trouvez cette ligne (seulement une partie de la ligne);
code:
starttable('100%', '<input type="radio" name="action" value="title" id="title" class="nobg"
ajoutez juste devant;
Code:
//for watermarking
starttable('100%', '<input type="radio" name="action" value="watermarks" id="watermarks"
class="nobg" /><label for="watermarks" accesskey="w" class="labelradio">' .
$lang_util_php['watermarks'] . '</label> (1)');
print '
<tr><td>
' . $lang_util_php['update_what'] . ' (2):<br />
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label
for="thumb" accesskey="w" class="labelradio">' . $lang_util_php['watermark_normal'] .
'</label><br />
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label
for="resized" accesskey="r" class="labelradio">' . $lang_util_php['watermark_image'] .
'</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg"
/><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['watermark_both'] .
'</label><br />
' . $lang_util_php['update_number'] . '
<input type="text" name="numpics" value="' . $defpicnum . '" size="5" /><br />
' . $lang_util_php['update_option'] . '<br /><br />
</td></tr>';
endtable();
print '<br />';
4. ouvrez le fichier config.php (dans la racine de votre galerie);
trouvez cette ligne;
Code:
function create_form(&$data)
Ajoutez ceci au-dessus de cette ligne;
code:
// Added for allowing user to select where to add watermarks on pics...
function form_watermark($text, $name)
{
global $CONFIG, $lang_config_php;
$value = $CONFIG[$name];
$bottomright_selected = ($value == 'bottomright') ? 'selected' : '';
$bottomleft_selected = ($value == 'bottomleft') ? 'selected' : '';
$topleftt_selected = ($value == 'topleftt') ? 'selected' : '';
$topright_selected = ($value == 'topright') ? 'selected' : '';
echo <<<EOT
<tr>
<td class="tableb">
$text
</td>
<td class="tableb" valign="top">
<select name="$name" class="listbox">
<option value="bottomright"
$bottomright_selected>{$lang_config_php['wm_bottomright']}</option>
<option value="bottomleft"
$bottomleft_selected>{$lang_config_php['wm_bottomleft']}</option>
<option value="topleftt"
$topleftt_selected>{$lang_config_php['wm_topleftt']}</option>
<option value="topright"
$topright_selected>{$lang_config_php['wm_topright']}</option>
</select>
</td>
</tr>
EOT;
}
// Added for allowing user to select which files to watermark...
function form_watermark2($text, $name)
{
global $CONFIG, $lang_config_php;
$value = $CONFIG[$name];
$both_selected = ($value == 'both') ? 'selected' : '';
$original_selected = ($value == 'original') ? 'selected' : '';
$resized_selected = ($value == 'resized') ? 'selected' : '';
echo <<<EOT
<tr>
<td class="tableb">
$text
</td>
<td class="tableb" valign="top">
<select name="$name" class="listbox">
<option value="both"
$both_selected>{$lang_config_php['wm_both']}</option>
<option value="original"
$original_selected>{$lang_config_php['wm_original']}</option>
<option value="resized"
$resized_selected>{$lang_config_php['wm_resized']}</option>
</select>
</td>
</tr>
EOT;
}
trouvez cette ligne;
Code:
case 10 :
form_number_dropdown($element[0], $element[1]);
break;
quelque lignes plus loin trouvez
Code:
die('Invalid action');
collez entre ces deux lignes
Code:
//Watermark place
case 11 :
form_watermark($element[0], $element[1]);
break;
//Which filest to watermark
case 12 :
form_watermark2($element[0], $element[1]);
break;
case 13 :
// do nothing
break;
default:
5. Exécutez ces commandes SQL avec phpMyAdmin or Webmin ou tout autre logiciel approprié;
insert into cpg11d_config (name, value) values ('enable_watermark', '1');
insert into cpg11d_config (name, value) values ('where_put_watermark', 'bottomright');
insert into cpg11d_config (name, value) values ('watermark_file', '/your/full/path/to/logo.png');
insert into cpg11d_config (name, value) values ('which_files_to_watermark', 'both');
avant d'exécuter ces commandes,vérifier le préfixe de vos tables de la base de données
coppermine (passez en mode administrateur,et dans le panneau de configuration de votre
galerie, vers le bas du panneau, vous devez voir apparaitre le préfixe des tables. Ou alors dans
phpMyAdmin vous pouvez voir le nom des tables de votre base de données coppermine.)
Ce préfixe est trés important pour taper les commandes
insert into cpg11d_config (en gras partie à modifier si nécéssaire)
commande qui déclare le chemin de votre logo de filigranage.
insert into cpg11d_config (name, value) values ('watermark_file', '/your/full/path/to/logo.png');
/your/full/path/to/logo.png cette partie est un chemin, pas une adresse type URL (http://....)
GOOD TIPS : Pour connaitre le chemin complet, demandez à votre fournisseur, ou alors essayez cette méthode :
tapez un chemin "bidon", uploadez une photo, un message d'erreur va fatalement s'afficher,
étudiez-le et vous trouverez le chemin de votre logo. Il ne vous restera plus qu'à copier cette
information dans la commande sql et l'exécuter.
TRES IMPORTANT :
avant d'uploader une image, passez par le panneau de configuration, et activer le "watermark" !
note : certains fournisseurs interdisent le safe mode pour des raisons de sécurité, demander à
l'activer si il accepte tant mieux pour vous (pour moi ça a été un "NIET" définitif), cette fonction
est opérationelle sur une galerie en local sur mon pc.
Pour conclure, pensez à créer votre logo de Copyright avant toute manip ! (JPEG ou PNG uniquement)
Et merci à Burpee pour ce mod !
Poubao
[edit by PYAP. Merci aussi à Poubao pour ce boulot. Excellent MOD]
[Merci également à Titooy pour ses judicieuses remarques !]