function showWatermarkOverImage($imagePath, $watermarkPath, $newImageName = "tmp", $position = 'bl') { XiptError::assert(JFile::exists($imagePath) && JFile::exists($watermarkPath), XiptText::_("FILE {$imagePath} AND {$watermarkPath} DOES NOT EXIST"), XiptError::ERROR); //original image $destinationType = self::getImageType($imagePath); $watermarkType = self::getImageType($watermarkPath); // Load image helper library as it is needed. require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'image.php'; $watermarkImage = cImageOpen($watermarkPath, $watermarkType); /*if(JFolder::exists(PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH)==false) JFolder::create(PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH); JFile::copy($imagePath,$newImagePath);*/ $imageImage = cImageOpen($imagePath, $destinationType); /*calculate watermark height and width from watermark image */ $watermarkWidth = imagesx($watermarkImage); $watermarkHeight = imagesy($watermarkImage); /*get original image size */ $size = getimagesize($imagePath); $dest_x = 0; //$size[0] - $watermarkWidth - 5; $dest_y = 0; //$size[1] - $watermarkHeight - 5; $xy = array(); $xy[0] =& $dest_x; $xy[1] =& $dest_y; $watermarkSize = array(); $watermarkSize[0] = $watermarkWidth; $watermarkSize[1] = $watermarkHeight; self::setPosotion($size, $watermarkSize, $watermarkImage, $position, $xy); imagecopymerge($imageImage, $watermarkImage, $dest_x, $dest_y, 0, 0, $watermarkSize[0], $watermarkSize[1], 100); /*first copy the image to tmp location , b'coz we don't want to destroy original image */ $newImagePath = PROFILETYPE_AVATAR_STORAGE_PATH . DS . $newImageName . '.' . JFile::getExt($imagePath); $newImageRefPath = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . $newImageName . '.' . JFile::getExt($imagePath); imagesavealpha($imageImage, true); ob_start(); // Test if type is png if ($destinationType == 'image/png' || $destinationType == 'image/x-png') { imagepng($imageImage); } elseif ($destinationType == 'image/gif') { imagegif($imageImage); } else { // We default to use jpeg imagejpeg($imageImage, null, 100); } $output = ob_get_contents(); ob_end_clean(); JFile::write($newImagePath, $output); // Free any memory from the existing image resources imagedestroy($imageImage); imagedestroy($watermarkImage); return $output ? $newImageRefPath : false; }
function generateThumbnail($imageName, $filename, $storage, $newData, $config) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'image.php'; $fileExt = JFile::getExt($filename); $thumbnailName = 'watermark_' . $newData->id . '_thumb.' . $fileExt; $storageThumbnail = $storage . DS . $thumbnailName; $watermarkPath = $storage . DS . $imageName . '.' . $fileExt; $watermarkThumbWidth = $config->get('xiThumbWidth', 80); $watermarkThumbHeight = $config->get('xiThumbHeight', 20); // create a transparent blank image // if type of watermark is text call ImageCreateTrueColor else //else call imageCreateTransparent if ($config->get('typeofwatermark', '0') == '0') { $dstimg = ImageCreateTrueColor($watermarkThumbWidth, $watermarkThumbHeight); } else { $dstimg = XiptLibImage::imageCreateTransparent($watermarkThumbWidth, $watermarkThumbHeight); } $watermarkType = XiptHelperImage::getImageType($watermarkPath); $srcimg = cImageOpen($watermarkPath, $watermarkType); //XITODO : also support other formats if (imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $watermarkThumbWidth, $watermarkThumbHeight, $config->get('xiWidth', 64), $config->get('xiHeight', 64))) { //fix for permissions imagepng($dstimg, $storageThumbnail); chmod($storageThumbnail, 0744); } else { XiptError::raiseWarning('XIPT_THUMB_WAR', 'THUMBNAIL NOT SUPPORTED'); } /*if(!cImageCreateThumb( $watermarkPath , $storageThumbnail , XiptHelperImage::getImageType($watermarkPath),$config->get(xiWidth,64)/2,$config->get(xiHeight,64)/2)); $info['msg'] .= sprintf(JText::_('ERROR MOVING UPLOADED FILE') , $storageThumbnail);*/ return; }