PDA

Просмотр полной версии : маска на картинку


enot
16.08.2007, 04:08
вот пытаюсь наложить логотипчик на картинку

$conf["image."]["file"] = "uploads/tx_ed/".$data['file'];
$conf["image."]["file."]["height"] = $height.'m';
$conf["image."]["file."]["width"] = $widht.'m';
$conf["image."]["imageLinkWrap"] = '1';
$conf["image."]["altText"] = $title;
$conf["image."]["titleText"] = $title;
// $conf["image."]['wrap'] = ' | '.$data['title'];
$conf["image."]["file."]["m."]["bgImg"] = "fileadmin/templates/ed/watermark2.jpg";
$conf["image."]["file."]["m."]["mask"] = "fileadmin/templates/ed/mask_whited.gif";
$conf["image."]["imageLinkWrap."]["enable"] = "1";
$conf["image."]["imageLinkWrap."]["bodyTag"] = "<BODY style=\"margin:4 4 4 4;\">";//.Pictures::getCounters();
$conf["image."]["imageLinkWrap."]["wrap"] = "<A title=\"".htmlspecialchars($title)."\" href=\"javascript:close();\"> | </A>";



$conf["image."]["imageLinkWrap."]["width"] = "800m";
$conf["image."]["imageLinkWrap."]["height"] = "600m";
$conf["image."]["imageLinkWrap."]["title"] = $title;
$conf["image."]["imageLinkWrap."]["JSwindow"] = "1";
$conf["image."]["imageLinkWrap."]["JSwindow."]["newWindow"] = "1";
$conf["image."]["imageLinkWrap."]["JSwindow."]["expand"] = "8,8";



$theImgCode=$cObj->IMAGE($conf["image."]);

вот такой код...
на уменьшенную картинку логотипчик наложился а на большую (та что октрывается в новом окне) нет.
в чем ошибка? и можно ли так вообще делать?

Valery Romanchev
16.08.2007, 23:09
сделать нормальное наложение логотипа с помощью тайповских библиотек, которые дергают imagemagic - довольно проблематично.
(особенно, если у клиента высокие требования к результату)

Я пробовал года полтора назад

В итоге - сделал обычным PHP кодом с использованием GD

<?php
/**
* Provide TCE and TCEforms functions for usage in own extension.
*
* @package TYPO3
*/
class tx_netshop_images {

/**
* function resizeImage($width, $height, $source, $target)
* Resizes the Image to the given values
*
* @param width int The maximum image width
* @param height int The maximum image height
* @param source String The source file
* @param target String The target file
*
* @return void
*/
// $dim_thumb=tx_netshop_images::imageResize('130', '170', '85', $fullname,$width, $height, $folderCurrent.'thumb/'.$item->data['item_id'].'.jpg');


// function imageResize($width, $height, $quality, $source, $width_orig, $height_orig, $target) {

function imageResize($code, $source, $target) {

if (!is_file($source)) return array(0,0);

switch ($code){
case 'thumb':
$width=130;
$height=170;
$quality=85;
break;
case 'small':
$width=50;
$height=60;
$quality=85;
break;
}

list($width_orig, $height_orig, $type, $attr) = @getimagesize($source);
if (!$width_orig) return array(100,100);

//width and maxH
$height_cur = round(($width / $width_orig) * $height_orig);
if ($height_cur > $height){
$width= round(($height / $height_orig) * $width_orig);
}
else {
$height=$height_cur;
}

// debug(array($width, $height, $quality, $source, $width_orig, $height_orig, $target));
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($source);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagedestroy($image);
imagejpeg($image_p, $target, $quality);
imagedestroy($image_p);

return array($width,$height);
}

function imageMakeWatermark ($source, $target) {

$quality=85;

list($width_orig, $height_orig, $type, $attr) = @getimagesize($source);

if ($width_orig == $height_orig) {
// $orientation = 'square';
$width=min(450,$width_orig); //'450';

} elseif ($width_orig > $height_orig ) {
// $orientation = 'landscape';
$width=min(580,$width_orig);
} else {
// $orientation = 'portret';
$width=min(368,$width_orig);
}


//width of the target is given only
$height = round(($width / $width_orig) * $height_orig);


// t3lib_div::debug($source,'source');
// t3lib_div::debug($target,'target');
if (intval($width_orig) < 350){
$watermark = imagecreatefrompng(PATH_site.'fileadmin/design/images/watermarkors_small.png');
$watermark_width = '250';
$watermark_height = '114';
}
else{
$watermark = imagecreatefrompng(PATH_site.'fileadmin/design/images/watermarkors_sm.png');
$watermark_width = '350';
$watermark_height = '159';
}
// $image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($source);
$image_p = imagecreatetruecolor($width, $height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagedestroy($image);


$dest_x = ($width / 2) - ($watermark_width / 2);
$dest_y = ($height / 2) - ($watermark_height / 2);

//imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagecopy($image_p, $watermark, $dest_x , $dest_y, 0, 0, $watermark_width, $watermark_height);
// imagecopyresampled($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height,
//$watermark_width, $watermark_height);
imagedestroy($watermark);

imagejpeg($image_p,$target);
imagedestroy($image_p);
return array($width,$height);
}


function imageUpdateSize($type, $uid, $width, $height) {
// $type can be '', 'thumb', 'small', 'water'
// Update clicks and click_ip of the link
$whereClause = "uid=$uid";
if($type) $type='_'.$type;
$updateFields = array(
'width'.$type => $width,
'height'.$type => $height,
);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_netshop_items' , $whereClause, $updateFields);
}



function createFolders($folderCurrent) {
if ($folderCurrent!=PATH_site) {
$fileContent='
<Files "*.jpg">
deny from all
</Files>
<Files "*.JPG">
deny from all
</Files>
';
t3lib_div::writeFile($folderCurrent.'.htaccess',$f ileContent);
$fileContent='
<Files "*.jpg">
Allow from all
</Files>
<Files "*.JPG">
Allow from all
</Files>
';
foreach (array("thumb", "small", "water") as $value){
t3lib_div::mkdir($folderCurrent.$value);
t3lib_div::writeFile($folderCurrent.$value.'/.htaccess',$fileContent);
}
}
}


}


?>

enot
20.08.2007, 00:27
Спасибо
а почему GD?
я думал imageMagick лучше все операции с картинками выполняет...
и кода меньше писать
у меня вот так получилось

/**
* Добавляет watermark на картинку $img
*
* @param string $img - файл с картинкой
* @param string $watermark_file - файл watermark
* @return boolean true - если все нормально иначе false
*/
function addWatermark($img, $watermark_file, $disslove = 15) {
$cmd = Pictures::addWatermarkCmd($img,$watermark_file,$di sslove);
if($cmd) {
exec($cmd);
return true;
}
else {
return false;
}
}

/**
* Возвращает команду для ImageMAgick для добавляет watermark на картинку $img
*
* @param string $img - файл с картинкой
* @param string $watermark_file - файл watermark
* @return string текст команда
*/
function addWatermarkCmd($img, $watermark_file, $disslove = 15) {
$data = getimagesize($img);
if($data === false) {
return false;
}

$W = Pictures::resize($watermark_file, $data);
if($W === false) {
return false;
}
$params = '-dissolve '.$disslove.' -gravity Center "'.$W .'" "'.$img.'"';
$cmd = t3lib_div::imageMagickCommand('composite', $params. ' "'.$img.'"');
return $cmd;
}

margol
03.08.2010, 13:41
офф-топ, пардон...