<span class="syntaxhtml"><br /><span class="syntaxdefault"><?php<br />$watermarkimage</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"watermark.png"</span><span class="syntaxkeyword">;<br /><br /></span><span class="syntaxcomment">//$file = basename($_GET['i']);<br /><br /></span><span class="syntaxdefault">$scriptDir </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> dirname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$_SERVER</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'SCRIPT_FILENAME'</span><span class="syntaxkeyword">]);<br /><br /></span><span class="syntaxdefault">$image </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $scriptDir</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'/'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$_GET</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'i'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault">$watermark </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $scriptDir</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'/'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$watermarkimage</span><span class="syntaxkeyword">;<br /><br /></span><span class="syntaxdefault">$im </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecreatefrompng</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$watermark</span><span class="syntaxkeyword">);<br /><br /></span><span class="syntaxdefault">$ext </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> substr</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">-</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">);<br /><br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">strtolower</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$ext</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'gif'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(!</span><span class="syntaxdefault">$im2 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecreatefromgif</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> echo </span><span class="syntaxstring">"Error opening $image!"</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> exit</span><span class="syntaxkeyword">;<br />}<br />}</span><span class="syntaxdefault"> else if</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">strtolower</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$ext</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'jpg'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(!</span><span class="syntaxdefault">$im2 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecreatefromjpeg</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> echo </span><span class="syntaxstring">"Error opening $image!"</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> exit</span><span class="syntaxkeyword">;<br />}<br />}</span><span class="syntaxdefault"> else if</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">strtolower</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$ext</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'png'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(!</span><span class="syntaxdefault">$im2 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecreatefrompng</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> echo </span><span class="syntaxstring">"Error opening $image!"</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> exit</span><span class="syntaxkeyword">;<br />}<br />}</span><span class="syntaxdefault"> else </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> die</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Error'</span><span class="syntaxkeyword">);<br />}<br /></span><span class="syntaxdefault">imagefilledrectangle</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0 </span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imagesy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">))-(</span><span class="syntaxdefault">imagesy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> imagesx</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> imagesy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> imagecolorallocatealpha</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 100</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">imagecopy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> $im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imagesx</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">)-(</span><span class="syntaxdefault">imagesx</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">))),</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imagesy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">))-(</span><span class="syntaxdefault">imagesy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">)),</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> imagesx</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> imagesy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">));<br /><br /></span><span class="syntaxdefault">$last_modified </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> gmdate</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'D, d M Y H:i:s T'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> filemtime </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">));<br /><br /></span><span class="syntaxdefault">header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Last-Modified: $last_modified"</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Content-Type: image/jpeg"</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">imagejpeg</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">NULL</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">95</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">imagedestroy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">imagedestroy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im2</span><span class="syntaxkeyword">);<br /><br /></span><span class="syntaxdefault">?><br /></span></span>
RewriteEngine on
RewriteRule ^(.*\.[jJ].*)$ watermark.php?i=$1
Leonick a dit:en fait, le problème que j'ai avec les watermarks automatiques, c'est que je n'ai pas réussi à trouver comment gérer la couleur/transparence en fonction de la photo :