The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Joomla - PHP watermark Script problem
Discuss PHP watermark Script problem in the PHP Development forum on Dev Shed. PHP watermark Script problem PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 23rd, 2012, 04:11 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 24 m 21 sec
Reputation Power: 0
|
|
|
Joomla - PHP watermark Script problem
Hi,
The attached script is from a plugin for Joomla, that overlays a watermark on an Image, Thumbnail & Avatar. It works, BUT it aligns the watermark (based on coordinates in input in the Joomla backend), from the TOP LEFT of the source image. I need it to align the watermark from the BOTTOM LEFT of the source image.
I am not much of a php expert, and maybe this is a simple change. I have tried a few things and wind up breaking the code. I have also asked the developer to make the changes for a fee with no luvk. I would love some help with this and AM willing to HIRE someone to do it if I need to.
I think, from my limited understanding, that changing this will affect the change on all of the images, the Image, Thumbnail & Avatar. That is fine.
Please help, this is driving me nuts!
I think this is the relevant line of code from line 355:
Code:
// Combine background image and watermark into a single output image
imagecopy($background, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight);
Code:
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php';
require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'image.php';
jimport('joomla.error.log');
if (!class_exists('PlgCommunityJsWatermark'))
{
/**
* PlgCommunityJsWatermark class.
*
* @package Extly.Plugins
* @subpackage jswatermark
* @since 1.0
*/
class PlgCommunityJsWatermark extends CApplications
{
public $name = "JsWatermark";
public $_name = 'jswatermark';
private $_path = '';
/**
* getConfiguration.
*
* @return array.
*
* @since 1.5
*/
public function getConfiguration()
{
static $configuration = null;
$params = new CParameter('');
if (is_null($configuration))
{
$plugin = & JPluginHelper::getPlugin('community', 'jswatermark');
$params = new CParameter($plugin->params);
$version = new JVersion;
$joomla = $version->getShortVersion();
$is_j15 = (substr($joomla, 0, 3) == '1.5');
$configuration = array(
'version' => '1.0',
'on_photo_create' => $params->get('on_photo_create', 1),
'on_profile_avatar_update' => $params->get('on_profile_avatar_update', 1),
'photo_watermark' => $params->get('photo_watermark', null),
'thumb_watermark' => $params->get('thumb_watermark', null),
'profile_watermark' => $params->get('profile_watermark', null),
'photo_watermarkx' => intval($params->get('photo_watermarkx', 0)),
'photo_watermarky' => intval($params->get('photo_watermarky', 0)),
'thumb_watermarkx' => intval($params->get('thumb_watermarkx', 0)),
'thumb_watermarky' => intval($params->get('thumb_watermarky', 0)),
'profile_watermarkx' => intval($params->get('profile_watermarkx', 0)),
'profile_watermarky' => intval($params->get('profile_watermarky', 0)),
'original' => intval($params->get('original', 0)),
'photo_width' => intval($params->get('photo_width', 0)),
'photo_height' => intval($params->get('photo_height', 0)),
'debug' => intval($params->get('debug', 0)),
);
$configuration['is_j15'] = $is_j15;
}
return $configuration;
}
/**
* onPhotoCreate.
*
* @param object $photo A photo
*
* @return nil.
*
* @since 1.5
*/
public function onPhotoCreate($photo)
{
$config = $this->getConfiguration();
if ($config['debug'])
{
$log = &JLog::getInstance('watermaks-for-js.log.' . date("Y-m-d") . '.php');
$log->addEntry(array('comment' => 'configuration ' . print_r($configuration, true)));
$log->addEntry(array('comment' => 'onPhotoCreate ' . print_r($photo, true)));
}
if ($config['on_photo_create'])
{
if ($config['debug'])
{
$log->addEntry(array('comment' => 'on_photo_create enabled.'));
}
$watermarkImage = $config['photo_watermark'];
if ($watermarkImage)
{
if ($config['debug'])
{
$log->addEntry(array('comment' => 'photo_watermark enabled.'));
}
if ($config['is_j15'])
{
$watermarkPath = JPATH_ROOT . DS . 'images' . DS . CString::str_ireplace('/', DS, $watermarkImage);
} else
{
$watermarkPath = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $watermarkImage);
}
$storageImage = $photo->image;
$storageImage = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $storageImage);
$originalImage = $photo->original;
$originalImage = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $originalImage);
$dstImage = $storageImage;
if ($config['original'])
{
$srcImage = $originalImage;
$configjs = CFactory::getConfig();
$displayWidth = $configjs->getInt('photodisplaysize');
$storageImageInfo = getimagesize($srcImage);
$fileType = $storageImageInfo['mime'];
$displayWidth = ($storageImageInfo[0] < $displayWidth) ? $storageImageInfo[0] : $displayWidth;
CImageHelper::resizeProportional($srcImage, $dstImage, $fileType, $displayWidth);
$srcImage = $dstImage;
}
else
{
$srcImage = $storageImage;
}
if (!JFile::exists($srcImage))
{
if ($config['debug'])
{
$log->addEntry(array('comment' => "photo_watermark File not found: {$srcImage}"));
}
return;
}
$storageImageInfo = getimagesize($srcImage);
if ($srcImage)
{
$fileType = $storageImageInfo['mime'];
$x = $config['photo_watermarkx'];
$y = $config['photo_watermarky'];
if ($config['debug'])
{
$log->addEntry(array('comment' => "photo_watermark addWatermark ({$srcImage}, {$dstImage}, {$fileType}, {$watermarkPath}, {$x}, {$y})."));
}
plgCommunityJsWatermark::addWatermark($srcImage, $dstImage, $fileType, $watermarkPath, $x, $y);
}
else
{
$msg = print_r($storageImageInfo, true);
$log->addEntry(array('comment' => "photo_watermark getimagesize problem: {$msg}"));
}
}
$watermarkImage = $config['thumb_watermark'];
if ($watermarkImage)
{
if ($config['debug'])
{
$log->addEntry(array('comment' => 'thumb_watermark enabled.'));
}
if ($config['is_j15'])
{
$watermarkPath = JPATH_ROOT . DS . 'images' . DS . CString::str_ireplace('/', DS, $watermarkImage);
} else
{
$watermarkPath = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $watermarkImage);
}
$storageImage = $photo->thumbnail;
$storageImage = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $storageImage);
if (!JFile::exists($storageImage))
{
if ($config['debug'])
{
$log->addEntry(array('comment' => "thumb_watermark File not found: {$storageImage}"));
}
return;
}
$storageImageInfo = getimagesize($storageImage);
if ($storageImageInfo)
{
$fileType = $storageImageInfo['mime'];
$x = $config['thumb_watermarkx'];
$y = $config['thumb_watermarky'];
if ($config['debug'])
{
$log->addEntry(array('comment' => "thumb_watermark addWatermark ({$storageImage}, {$storageImage}, {$fileType}, {$watermarkPath}, {$x}, {$y})."));
}
plgCommunityJsWatermark::addWatermark($storageImage, $storageImage, $fileType, $watermarkPath, $x, $y);
}
else
{
$msg = print_r($storageImageInfo, true);
$log->addEntry(array('comment' => "thumb_watermark getimagesize problem: {$msg}"));
}
}
}
}
/**
* onProfileAvatarUpdate
*
* @param integer $userid Param
* @param string $oldFile Param
* @param string $photo Param
*
* @return nil
*
* @since 1.5
*/
public function onProfileAvatarUpdate($userid, $oldFile, $photo)
{
$config = $this->getConfiguration();
if ($config['debug'])
{
$log = &JLog::getInstance('watermaks-for-js.log.' . date("Y-m-d") . '.php');
$log->addEntry(array('comment' => 'configuration ' . print_r($configuration, true)));
$log->addEntry(array('comment' => "onProfileAvatarUpdate ({$userid}, {$oldFile}, {$photo})"));
}
if ($config['on_profile_avatar_update'])
{
if ($config['debug'])
{
$log->addEntry(array('comment' => 'on_profile_avatar_update enabled.'));
}
$watermarkImage = $config['profile_watermark'];
if ($watermarkImage)
{
if ($config['debug'])
{
$log->addEntry(array('comment' => 'profile_watermark enabled.'));
}
if ($config['is_j15'])
{
$watermarkPath = JPATH_ROOT . DS . 'images' . DS . CString::str_ireplace('/', DS, $watermarkImage);
} else
{
$watermarkPath = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $watermarkImage);
}
$storageImage = $photo;
$storageImage = JPATH_ROOT . DS . CString::str_ireplace('/', DS, $storageImage);
if (!JFile::exists($storageImage))
{
if ($config['debug'])
{
$log->addEntry(array('comment' => "profile_watermark File not found: {$storageImage}"));
}
return;
}
$storageImageInfo = getimagesize($storageImage);
if ($storageImageInfo)
{
$fileType = $storageImageInfo['mime'];
$x = $config['profile_watermarkx'];
$y = $config['profile_watermarky'];
if ($config['debug'])
{
$log->addEntry(array('comment' => "profile_watermark addWatermark ({$storageImage}, {$storageImage}, {$fileType}, {$watermarkPath}, {$x}, {$y})."));
}
plgCommunityJsWatermark::addWatermark($storageImage, $storageImage, $fileType, $watermarkPath, $x, $y);
}
else
{
$msg = print_r($storageImageInfo, true);
$log->addEntry(array('comment' => "profile_watermark getimagesize problem: {$msg}"));
}
}
}
}
/**
* addWatermark
*
* @param integer $backgroundImagePath Param
* @param string $destinationPath Param
* @param string $destinationType Param
* @param string $watermarkImagePath Param
* @param string $positionX Param
* @param string $positionY Param
* @param string $deleteBackgroundImage Param
*
* @return nil
*
* @since 1.5
*/
static public function addWatermark(
$backgroundImagePath, $destinationPath, $destinationType, $watermarkImagePath, $positionX = 0, $positionY = 0, $deleteBackgroundImage = true)
{
// Set output quality
$config = CFactory::getConfig();
$imgQuality = $config->get('output_image_quality');
$pngQuality = ($imgQuality - 100) / 11.111111;
$pngQuality = round(abs($pngQuality));
$watermarkInfo = getimagesize($watermarkImagePath);
if (!$watermarkInfo)
{
echo "ERROR: watermarkImagePath {$watermarkImagePath} error - getimagesize!";
return;
}
$background = CImageHelper::open($backgroundImagePath, $destinationType);
$watermark = CImageHelper::open($watermarkImagePath, $watermarkInfo['mime']);
list( $backgroundWidth, $backgroundHeight ) = getimagesize($backgroundImagePath);
// Try to make the watermark image transparent
imagecolortransparent($watermark, imagecolorat($watermark, 0, 0));
// Get overlay image width and hight
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);
// Combine background image and watermark into a single output image
imagecopy($background, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight);
// Output
ob_start();
// Test if type is png
if ($destinationType == 'image/png' || $destinationType == 'image/x-png')
{
imagepng($background, null, $pngQuality);
} elseif ($destinationType == 'image/gif')
{
imagegif($background);
} else
{
imagejpeg($background, null, $imgQuality);
}
$output = ob_get_contents();
ob_end_clean();
// Delete old image
if (JFile::exists($backgroundImagePath) && $deleteBackgroundImage)
{
JFile::delete($backgroundImagePath);
}
// Free any memory from the existing image resources
imagedestroy($background);
imagedestroy($watermark);
return JFile::write($destinationPath, $output);
}
}
}
Please Help, this is driving me nuts!
|

November 23rd, 2012, 07:39 PM
|
 |
JavaScript is not spelt java
|
|
Join Date: Feb 2011
Location: Landan, England
|
|
I would experiment:
PHP Code:
imagecopy($background, $watermark, $positionX, $positionY, 0, $positionY - $watermarkHeight, $watermarkWidth, $watermarkHeight);
|

November 26th, 2012, 07:18 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 24 m 21 sec
Reputation Power: 0
|
|
Well, trying a few things with no luck:
Code:
imagecopy($background, $watermark, $positionX, $positionY, 0, imagesy($displayHeight), $watermarkWidth, $watermarkHeight);
Code:
imagecopy($background, $watermark, $positionX, $positionY, 0, $positionY - imagesy($displayHeight), $watermarkWidth, $watermarkHeight);
Code:
imagecopy($background, $watermark, $positionX, $positionY, 0, $positionY - $srcHeight, $watermarkWidth, $watermarkHeight);
Any ideas anyone? Thanks for any help here!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|