mercredi 15 avril 2015

how to phpthumb gd_watermark watermark dynamically scale inside orginal image

this code worked but not scaling watermark. if small image then very big watermark, if big image then very small watermark . so this my code



public function watermark($fullPath)
{

if(StoreImagesConfig::get('watermark_active'))
{
$pic = PhpThumbFactory::create($fullPath);
$pos = StoreImagesConfig::get('watermark_position_vertical').StoreImagesConfig::get('watermark_position_horizontal');

try {
$watermark = PhpThumbFactory::create(Yii::getPathOfAlias('webroot.uploads') . '/watermark.png');

$pic->addWatermark(
$watermark,
$pos,
StoreImagesConfig::get('watermark_opacity'),
0,
0
);
$pic->save($fullPath);
} catch(Exception $e) {
// pass
}
}
}


gd_watermark.php addWatermark function



public function addWatermark($wm, $pos, $opacity, $offsetX, $offsetY, $that)
{
$picDim = $that->getCurrentDimensions();
$wmDim = $wm->getCurrentDimensions();

$wmPosX = $offsetX;
$wmPosY = $offsetY;

if(preg_match('/right|east/i', $pos)){$wmPosX += $picDim['width'] - $wmDim['width'];}
else if(!preg_match('/left|west/i', $pos)){$wmPosX += intval($picDim['width']/2 - $wmDim['width']/2);}

if(preg_match('/bottom|lower|south/i', $pos)){$wmPosY += $picDim['height'] - $wmDim['height'];}
else if(!preg_match('/upper|top|north/i', $pos)){$wmPosY += intval($picDim['height']/2 - $wmDim['height']/2);}

$workingImage = $that->getOldImage();

$wmImage = ($wm->getWorkingImage() ? $wm->getWorkingImage() : $wm->getOldImage());

$this->imageCopyMergeAlpha($workingImage, $wmImage, $wmPosX, $wmPosY, 0, 0, $wmDim['width'], $wmDim['height'], $opacity);

$that->setWorkingImage($workingImage);
return $that;
}


how to resize watermark inside orginal image....


Aucun commentaire:

Enregistrer un commentaire