pelloquin.com

the web factory

Joomla extensions

Quality Joomla extensions




Accueil arrow Blog arrow How to add a watermak in Sobi2 Galery plugin
How to add a watermak in Sobi2 Galery plugin
Écrit par Cédric Pelloquin   
12-08-2010

Some users asked me how to add a watermark into the Sobi2 Galery plugin RC2.4. A solution was proposed in the sobi2 forum . It work fine, but have some inconveniences:

  • The watermark is just added for the display the original image dont contains any watermark and an advanced user can for easy get the images: the link on the images is http://www.site.com/watermark.php?path=http://www.site.com/com_sobi2/gallery/67/67_image_2.jpg then the user copy past the  http://www.site.com/com_sobi2/gallery/67/67_image_2.jpg and have the original image.
  • The code use the  imagecreatefromjpeg php function need that your server allows the allow_url_fopen, and php > 4.3.

The goal is to add the watermark to the original images. I my solution, the watermark is added before the galery image creation and will be into the normal and preview image (watermark is redimensioned).

 

You need to open the gallery.class.php release RC2.4 and search this code around the line 790:

            case 2:
                if(!($image_p = imagecreatetruecolor($width, $height)))
                    return false;
                if(!($image = imagecreatefromjpeg($file)))
                    return false;
                if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig)))
                    return false;
                if(!(imagejpeg($image_p, $file,$config->key( "general", "jpeg_image_quality", 75 ))))
                    return false;
            break;

and adding theses bold lines:

 

 

             case 2:
                if(!($image_p = imagecreatetruecolor($width, $height)))
                    return false;
                if(!($image = imagecreatefromjpeg($file)))
                    return false;


$watermark = @imagecreatefrompng('images/watermark.png');
$imagewidth = imagesx($image);
$imageheight = imagesy($image);  
$watermarkwidth =  imagesx($watermark);
$watermarkheight =  imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/1);
$startheight = (($imageheight - $watermarkheight)/1);
imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);

                if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig)))
                    return false;
                if(!(imagejpeg($image_p, $file,$config->key( "general", "jpeg_image_quality", 75 ))))
                    return false;
            break;

This sample is for the jpg images type, but you can for easy apply this for png/gif, by managing the case 1 and case 2 with the appropriate php function.

Dernière mise à jour : ( 25-01-2011 )
 
Suivant >

Partenaire Suisse

annuaire web suisse de référencement Vous cherchez un bon annuaire:

  • Suisse?
  • Pagerank de 4?

L'annuaire web suisse de référencement est pour vous!

login






Mot de passe oublié ?
Pas encore de compte ? Enregistrez-vous
Joomla Templates by Joomlashack