Показать сообщение отдельно
Старый 16.08.2007, 23:09   #2
Valery Romanchev
Administrator
 
Аватар для Valery Romanchev
 
Регистрация: 23.08.2003
Адрес: Moscow, Russia
Сообщений: 1,926
Отправить сообщение для Valery Romanchev с помощью Skype™
По умолчанию

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

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

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

PHP код:
 <?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){
               
$widthround(($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$image0000$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$image0000$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_y00$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',$fileContent);
          
$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);
          }
}
     }


}


?>
__________________
Веб-студия ТТЛАБ
www.ttlab.ru
Valery Romanchev вне форума   Ответить с цитированием