Jump to content

Ayuda con maca de agua en imagenes


Bagheera

Recommended Posts

O tambien....

Hi all,
i’ve updated function for regenerating images to insert watermark. it’s necessary to create file img/p/watermark.gif with watermark – gif file with transparrent background.
in classess/Tools.php add:


function watermarkByImage(
$imagepath,
$watermarkpath,
$outputpath,
$transparency = 80,
$Xoffset = 0,
$Yoffset = 0,
$Xalign = "middle",
$Yalign = "bottom" //could use "top, "middle", "bottom
)
{
$image = imagecreatefromjpeg($imagepath);
$imagew = imagecreatefromgif($watermarkpath); //zjistime jejich velikost
list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkpath);
list($imageWidth, $imageHeight) = getimagesize($imagepath);
$xpos = 0;
$ypos = 0; //podle parametru funkce upravime promene //xpos a ypos
if ($Xalign == "middle") { $xpos = $imageWidth/2 - $watermarkWidth/2 + $Xoffset; }
if ($Xalign == "left") { $xpos = 0 + $Xoffset; }
if ($Xalign == "right") { $xpos = $imageWidth - $watermarkWidth - $Xoffset; }
if ($Yalign == "middle") { $ypos = $imageHeight/2 - $watermarkHeight/2 + $Yoffset; }
if ($Yalign == "top") { $ypos = 0 + $Yoffset; }
if ($Yalign == "bottom") { $ypos = $imageHeight - $watermarkHeight - $Yoffset; }
imagecopymerge($image, //zdrojovy obrazek
$imagew,
$xpos,
$ypos,
0, 0, $watermarkWidth, $watermarkHeight, $transparency);
return imagejpeg($image, $outputpath, 100);
}

----------------------------------------------------------------------------------------------------------------
and then admin/tabs/AdminImages.php :

/* Regenerate products images */
$errors = false;
foreach ($productsImages AS $k => $image)
{
if (file_exists(_PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'.jpg'))
$waterfile = _PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'-watermark.jpg';
Tools::watermarkByImage(_PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'.jpg', _PS_PROD_IMG_DIR_.'watermark.gif', $waterfile, 23, 0, 0, 'right');

foreach ($productsTypes AS $k => $imageType)
{
$wm = ($imageType['name'] == 'thickbox' || $imageType['name'] == 'large') ? '-watermark' : '';
$file['tmp_name'] = _PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].$wm.'.jpg';
$file['type'] = 'image/jpg';
$newFile = _PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'-'.stripslashes($imageType['name']).'.jpg';
if (!imageResize($file, $newFile, intval($imageType['width']), intval($imageType['height'])))
$errors = true;

}
}

--------------------------------------------------
Ondrej Svoboda
Moto-Online.cz

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...