Joomla 1.5 Хочу прикрутить функцию watermark к стандартному com_media

Тема в разделе "Программирование", создана пользователем andron_2006_83, 13.07.2010.

  1. Offline

    andron_2006_83 Недавно здесь

    Регистрация:
    16.08.2008
    Сообщения:
    17
    Симпатии:
    0
    Пол:
    Мужской
    ТЕМА закрыта...:)
    Все решил сам...
    Заменяем весь код в файле /administrator/components/com_media/controllers/file.php
    на код ниже, в тотже каталог ложим файл watermark.png
    Функция накладывает watemark(по центру) только на картинки с расширением .jpg которые больше по высоте и ширене чем watermark.png мне этого хватает кто хочет пусь експерементирует...
    :) сюда кому чего нежалко R229815771129 Z404492136425 .......
    Код (CODE):
    1. <?php
    2. /**
    3.  * @version     $Id: file.php 14401 2010-01-26 14:10:00Z louis $
    4.  * @package     Joomla
    5.  * @subpackage  Content
    6.  * @copyright   Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
    7.  * @license     GNU/GPL, see LICENSE.php
    8.  * Joomla! is free software. This version may have been modified pursuant to the
    9.  * GNU General Public License, and as distributed it includes or is derivative
    10.  * of works licensed under the GNU General Public License or other free or open
    11.  * source software licenses. See COPYRIGHT.php for copyright notices and
    12.  * details.
    13.  */
    14.  
    15. // Check to ensure this file is included in Joomla!
    16. defined('_JEXEC') or die( 'Restricted access' );
    17.  
    18. jimport('joomla.filesystem.file');
    19. jimport('joomla.filesystem.folder');
    20.  
    21. /**
    22.  * Weblinks Weblink Controller
    23.  *
    24.  * @package     Joomla
    25.  * @subpackage  Weblinks
    26.  * @since 1.5
    27.  */
    28. class MediaControllerFile extends MediaController
    29. {
    30.  
    31.     /**
    32.      * Upload a file
    33.      *
    34.      * @since 1.5
    35.      */
    36.     function upload()
    37.     {
    38.         global $mainframe;
    39.  
    40.         // Check for request forgeries
    41.         JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
    42.  
    43.         $file       = JRequest::getVar( 'Filedata', '', 'files', 'array' );
    44.         $folder     = JRequest::getVar( 'folder', '', '', 'path' );
    45.         $format     = JRequest::getVar( 'format', 'html', '', 'cmd');
    46.         $return     = JRequest::getVar( 'return-url', null, 'post', 'base64' );
    47.         $err        = null;
    48.  
    49.         // Set FTP credentials, if given
    50.         jimport('joomla.client.helper');
    51.         JClientHelper::setCredentialsFromRequest('ftp');
    52.  
    53.         // Make the filename safe
    54.         jimport('joomla.filesystem.file');
    55.         $file['name']   = JFile::makeSafe($file['name']);
    56.  
    57.         if (isset($file['name'])) {
    58.             $filepath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.strtolower($file['name']));
    59.              
    60.              function waterMark($original, $out, $watermark)
    61.         {
    62.         $znak_hw = getimagesize($watermark);
    63.         $foto_hw = getimagesize($original);
    64.         $znak = imagecreatefrompng ($watermark);
    65.         $foto = imagecreatefromjpeg ($original);
    66.         if ($foto_hw[0] > $znak_hw[0] and $foto_hw[1] > $znak_hw[1]) imagecopy ($foto,$znak, (($foto_hw[0]/2) - ($znak_hw[0]/2)), (($foto_hw[1]/2) - ($znak_hw[1]/2)), 0, 0, $znak_hw[0], $znak_hw[1]);
    67.         imagejpeg ($foto, $out, "100");
    68.         imagedestroy ($znak);
    69.         imagedestroy ($foto);
    70.         }
    71.         $watermark = JPATH_SITE . DS .'administrator'. DS .'components'. DS .'com_media'. DS .'controllers'. DS .'watermark.png';
    72.         if (strtolower(JFile::getExt($file['name'])) == 'jpg') waterMark($file['tmp_name'], $file['tmp_name'], $watermark);
    73.                          
    74.             if (!MediaHelper::canUpload( $file, $err )) {
    75.                 if ($format == 'json') {
    76.                     jimport('joomla.error.log');
    77.                     $log = &JLog::getInstance('upload.error.php');
    78.                     $log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err));
    79.                     header('HTTP/1.0 415 Unsupported Media Type');
    80.                     jexit('Error. Unsupported Media Type!');
    81.                 } else {
    82.                     JError::raiseNotice(100, JText::_($err));
    83.                     // REDIRECT
    84.                     if ($return) {
    85.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    86.                     }
    87.                     return;
    88.                 }
    89.             }
    90.  
    91.             if (JFile::exists($filepath)) {
    92.                 if ($format == 'json') {
    93.                     jimport('joomla.error.log');
    94.                     $log = &JLog::getInstance('upload.error.php');
    95.                     $log->addEntry(array('comment' => 'File already exists: '.$filepath));
    96.                     header('HTTP/1.0 409 Conflict');
    97.                     jexit('Error. File already exists');
    98.                 } else {
    99.                     JError::raiseNotice(100, JText::_('Error. File already exists'));
    100.                     // REDIRECT
    101.                     if ($return) {
    102.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    103.                     }
    104.                     return;
    105.                 }
    106.             }
    107.            
    108.             if (!JFile::upload($file['tmp_name'], $filepath)) {
    109.                 if ($format == 'json') {
    110.                     jimport('joomla.error.log');
    111.                     $log = &JLog::getInstance('upload.error.php');
    112.                     $log->addEntry(array('comment' => 'Cannot upload: '.$filepath));
    113.                     header('HTTP/1.0 400 Bad Request');
    114.                     jexit('Error. Unable to upload file');
    115.                 } else {
    116.                     JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
    117.                     // REDIRECT
    118.                     if ($return) {
    119.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    120.                     }
    121.                     return;
    122.                 }
    123.             } else {
    124.                 if ($format == 'json') {
    125.                     jimport('joomla.error.log');
    126.                     $log = &JLog::getInstance();
    127.                     $log->addEntry(array('comment' => $folder));
    128.                     jexit('Upload complete');
    129.                 } else {
    130.                     $mainframe->enqueueMessage(JText::_('Upload complete'));
    131.                     // REDIRECT
    132.                     if ($return) {
    133.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    134.                     }
    135.                     return;
    136.                 }
    137.             }
    138.         } else {
    139.             $mainframe->redirect('index.php', 'Invalid Request', 'error');
    140.         }
    141.     }
    142.  
    143.     /**
    144.      * Deletes paths from the current path
    145.      *
    146.      * @param string $listFolder The image directory to delete a file from
    147.      * @since 1.5
    148.      */
    149.     function delete()
    150.     {
    151.         global $mainframe;
    152.  
    153.         JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
    154.  
    155.         // Set FTP credentials, if given
    156.         jimport('joomla.client.helper');
    157.         JClientHelper::setCredentialsFromRequest('ftp');
    158.  
    159.         // Get some data from the request
    160.         $tmpl   = JRequest::getCmd( 'tmpl' );
    161.         $paths  = JRequest::getVar( 'rm', array(), '', 'array' );
    162.         $folder = JRequest::getVar( 'folder', '', '', 'path');
    163.  
    164.         // Initialize variables
    165.         $msg = array();
    166.         $ret = true;
    167.  
    168.         if (count($paths)) {
    169.             foreach ($paths as $path)
    170.             {
    171.                 if ($path !== JFile::makeSafe($path)) {
    172.                     JError::raiseWarning(100, JText::_('Unable to delete:').htmlspecialchars($path, ENT_COMPAT, 'UTF-8').' '.JText::_('WARNFILENAME'));
    173.                     continue;
    174.                 }
    175.  
    176.                 $fullPath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.$path);
    177.                 if (is_file($fullPath)) {
    178.                     $ret |= !JFile::delete($fullPath);
    179.                 } else if (is_dir($fullPath)) {
    180.                     $files = JFolder::files($fullPath, '.', true);
    181.                     $canDelete = true;
    182.                     foreach ($files as $file) {
    183.                         if ($file != 'index.html') {
    184.                             $canDelete = false;
    185.                         }
    186.                     }
    187.                     if ($canDelete) {
    188.                         $ret |= !JFolder::delete($fullPath);
    189.                     } else {
    190.                         JError::raiseWarning(100, JText::_('Unable to delete:').$fullPath.' '.JText::_('Not Empty!'));
    191.                     }
    192.                 }
    193.             }
    194.         }
    195.         if ($tmpl == 'component') {
    196.             // We are inside the iframe
    197.             $mainframe->redirect('index.php?option=com_media&view=mediaList&folder='.$folder.'&tmpl=component');
    198.         } else {
    199.             $mainframe->redirect('index.php?option=com_media&folder='.$folder);
    200.         }
    201.     }
    202. }


     
    Последнее редактирование: 14.07.2010
  2.  
  3. Jkr
    Offline

    Jkr Группа поддержки

    Регистрация:
    04.08.2006
    Сообщения:
    464
    Симпатии:
    27
    Пол:
    Мужской
    А где лежит сама картинка watermark.png?
     
  4. Offline

    andron_2006_83 Недавно здесь

    Регистрация:
    16.08.2008
    Сообщения:
    17
    Симпатии:
    0
    Пол:
    Мужской
    в корне сайта...
     
  5. Offline

    botanist Активист => Cпециалист <=

    Регистрация:
    15.02.2009
    Сообщения:
    461
    Симпатии:
    49
    Пол:
    Мужской
    А это $file['tmp_name'] откуда взялось. Инициализации не вижу.
     
  6. Offline

    andron_2006_83 Недавно здесь

    Регистрация:
    16.08.2008
    Сообщения:
    17
    Симпатии:
    0
    Пол:
    Мужской
    $file['tmp_name'] это файл-картинка который мы загружаем...
    Вообще это выглядит так:
    Код (CODE):
    1. <?php
    2. /**
    3.  * @version     $Id: file.php 14401 2010-01-26 14:10:00Z louis $
    4.  * @package     Joomla
    5.  * @subpackage  Content
    6.  * @copyright   Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
    7.  * @license     GNU/GPL, see LICENSE.php
    8.  * Joomla! is free software. This version may have been modified pursuant to the
    9.  * GNU General Public License, and as distributed it includes or is derivative
    10.  * of works licensed under the GNU General Public License or other free or open
    11.  * source software licenses. See COPYRIGHT.php for copyright notices and
    12.  * details.
    13.  */
    14.  
    15. // Check to ensure this file is included in Joomla!
    16. defined('_JEXEC') or die( 'Restricted access' );
    17.  
    18. jimport('joomla.filesystem.file');
    19. jimport('joomla.filesystem.folder');
    20.  
    21. /**
    22.  * Weblinks Weblink Controller
    23.  *
    24.  * @package     Joomla
    25.  * @subpackage  Weblinks
    26.  * @since 1.5
    27.  */
    28. class MediaControllerFile extends MediaController
    29. {
    30.  
    31.     /**
    32.      * Upload a file
    33.      *
    34.      * @since 1.5
    35.      */
    36.     function upload()
    37.     {
    38.         global $mainframe;
    39.  
    40.         // Check for request forgeries
    41.         JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
    42.  
    43.         $file       = JRequest::getVar( 'Filedata', '', 'files', 'array' );
    44.         $folder     = JRequest::getVar( 'folder', '', '', 'path' );
    45.         $format     = JRequest::getVar( 'format', 'html', '', 'cmd');
    46.         $return     = JRequest::getVar( 'return-url', null, 'post', 'base64' );
    47.         $err        = null;
    48.  
    49.         // Set FTP credentials, if given
    50.         jimport('joomla.client.helper');
    51.         JClientHelper::setCredentialsFromRequest('ftp');
    52.  
    53.         // Make the filename safe
    54.         jimport('joomla.filesystem.file');
    55.         $file['name']   = JFile::makeSafe($file['name']);
    56.        
    57.                
    58.         if (isset($file['name'])) {
    59.             $filepath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.strtolower($file['name']));
    60.        ?>



    Где то сдесь мы прикручиваем думаю то неважно:

    Код (CODE):
    1. <?php
    2. function waterMark($original, $watermark, $placement = 'bottom=5,right=5', $destination = null)
    3.         {
    4.         $info_o = @getImageSize($original);
    5.         if (!$info_o)
    6.          return false;
    7.         $info_w = @getImageSize($watermark);
    8.         if (!$info_w)
    9.          return false;
    10.  
    11.         list ($vertical, $horizontal) = split(',', $placement,2);
    12.         list($vertical, $sy) = split('=', trim($vertical),2);
    13.         list($horizontal, $sx) = split('=', trim($horizontal),2);
    14.  
    15.         switch (trim($vertical)) {
    16.          case 'bottom':
    17.          $y = $info_o[1] - $info_w[1] - (int)$sy;
    18.          break;
    19.           case 'middle':
    20.          $y = ceil($info_o[1]/2) - ceil($info_w[1]/2) + (int)$sy;
    21.          break;
    22.          default:
    23.          $y = (int)$sy;
    24.          break;
    25.         }
    26.  
    27.          switch (trim($horizontal)) {
    28.           case 'right':
    29.          $x = $info_o[0] - $info_w[0] - (int)$sx;
    30.          break;
    31.         case 'center':
    32.          $x = ceil($info_o[0]/2) - ceil($info_w[0]/2) + (int)$sx;
    33.          break;
    34.         default:
    35.          $x = (int)$sx;
    36.          break;
    37.         }
    38.  
    39.         header("Content-Type: ".$info_o['mime']);
    40.  
    41.         $original = @imageCreateFromString(file_get_contents($original));
    42.         $watermark = @imageCreateFromString(file_get_contents($watermark));
    43.         $out = imageCreateTrueColor($info_o[0],$info_o[1]);
    44.  
    45.         imageCopy($out, $original, 0, 0, 0, 0, $info_o[0], $info_o[1]);
    46.         if( ($info_o[0] > 250) && ($info_o[1] > 250) )
    47.         {
    48.         imageCopy($out, $watermark, $x, $y, 0, 0, $info_w[0], $info_w[1]);
    49.         }
    50.  
    51.         switch ($info_o[2]) {
    52.         case 1:
    53.          imageGIF($out);
    54.          break;
    55.         case 2:
    56.          imageJPEG($out);
    57.          break;
    58.         case 3:
    59.          imagePNG($out);
    60.          break;
    61.          }
    62.  
    63.         imageDestroy($out);
    64.         imageDestroy($original);
    65.         imageDestroy($watermark);
    66.  
    67.         return true;
    68.         }
    69.        
    70.         waterMark($file['tmp_name'], $watermark=JPATH_SITE . DS .'watermark.png', $placement = 'bottom=5,right=5', $destination = null);        
    71.   ?>


    продолжение
    Код (CODE):
    1. <?php
    2. if (!MediaHelper::canUpload( $file, $err )) {
    3.                 if ($format == 'json') {
    4.                     jimport('joomla.error.log');
    5.                     $log = &JLog::getInstance('upload.error.php');
    6.                     $log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err));
    7.                     header('HTTP/1.0 415 Unsupported Media Type');
    8.                     jexit('Error. Unsupported Media Type!');
    9.                 } else {
    10.                     JError::raiseNotice(100, JText::_($err));
    11.                     // REDIRECT
    12.                     if ($return) {
    13.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    14.                     }
    15.                     return;
    16.                 }
    17.             }
    18.  
    19.             if (JFile::exists($filepath)) {
    20.                 if ($format == 'json') {
    21.                     jimport('joomla.error.log');
    22.                     $log = &JLog::getInstance('upload.error.php');
    23.                     $log->addEntry(array('comment' => 'File already exists: '.$filepath));
    24.                     header('HTTP/1.0 409 Conflict');
    25.                     jexit('Error. File already exists');
    26.                 } else {
    27.                     JError::raiseNotice(100, JText::_('Error. File already exists'));
    28.                     // REDIRECT
    29.                     if ($return) {
    30.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    31.                     }
    32.                     return;
    33.                 }
    34.             }
    35.  
    36.             if (!JFile::upload($file['tmp_name'], $filepath)) {
    37.                 if ($format == 'json') {
    38.                     jimport('joomla.error.log');
    39.                     $log = &JLog::getInstance('upload.error.php');
    40.                     $log->addEntry(array('comment' => 'Cannot upload: '.$filepath));
    41.                     header('HTTP/1.0 400 Bad Request');
    42.                     jexit('Error. Unable to upload file');
    43.                 } else {
    44.                     JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
    45.                     // REDIRECT
    46.                     if ($return) {
    47.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    48.                     }
    49.                     return;
    50.                 }
    51.             } else {
    52.                 if ($format == 'json') {
    53.                     jimport('joomla.error.log');
    54.                     $log = &JLog::getInstance();
    55.                     $log->addEntry(array('comment' => $folder));
    56.                     jexit('Upload complete');
    57.                 } else {
    58.                     $mainframe->enqueueMessage(JText::_('Upload complete'));
    59.                     // REDIRECT
    60.                     if ($return) {
    61.                         $mainframe->redirect(base64_decode($return).'&folder='.$folder);
    62.                     }
    63.                     return;
    64.                 }
    65.             }
    66.         } else {
    67.             $mainframe->redirect('index.php', 'Invalid Request', 'error');
    68.         }
    69.     }
    70.  
    71.     /**
    72.      * Deletes paths from the current path
    73.      *
    74.      * @param string $listFolder The image directory to delete a file from
    75.      * @since 1.5
    76.      */
    77.     function delete()
    78.     {
    79.         global $mainframe;
    80.  
    81.         JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
    82.  
    83.         // Set FTP credentials, if given
    84.         jimport('joomla.client.helper');
    85.         JClientHelper::setCredentialsFromRequest('ftp');
    86.  
    87.         // Get some data from the request
    88.         $tmpl   = JRequest::getCmd( 'tmpl' );
    89.         $paths  = JRequest::getVar( 'rm', array(), '', 'array' );
    90.         $folder = JRequest::getVar( 'folder', '', '', 'path');
    91.  
    92.         // Initialize variables
    93.         $msg = array();
    94.         $ret = true;
    95.  
    96.         if (count($paths)) {
    97.             foreach ($paths as $path)
    98.             {
    99.                 if ($path !== JFile::makeSafe($path)) {
    100.                     JError::raiseWarning(100, JText::_('Unable to delete:').htmlspecialchars($path, ENT_COMPAT, 'UTF-8').' '.JText::_('WARNFILENAME'));
    101.                     continue;
    102.                 }
    103.  
    104.                 $fullPath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.$path);
    105.                 if (is_file($fullPath)) {
    106.                     $ret |= !JFile::delete($fullPath);
    107.                 } else if (is_dir($fullPath)) {
    108.                     $files = JFolder::files($fullPath, '.', true);
    109.                     $canDelete = true;
    110.                     foreach ($files as $file) {
    111.                         if ($file != 'index.html') {
    112.                             $canDelete = false;
    113.                         }
    114.                     }
    115.                     if ($canDelete) {
    116.                         $ret |= !JFolder::delete($fullPath);
    117.                     } else {
    118.                         JError::raiseWarning(100, JText::_('Unable to delete:').$fullPath.' '.JText::_('Not Empty!'));
    119.                     }
    120.                 }
    121.             }
    122.         }
    123.         if ($tmpl == 'component') {
    124.             // We are inside the iframe
    125.             $mainframe->redirect('index.php?option=com_media&view=mediaList&folder='.$folder.'&tmpl=component');
    126.         } else {
    127.             $mainframe->redirect('index.php?option=com_media&folder='.$folder);
    128.         }
    129.     }
    130. }
    131. ?>
     
    Последнее редактирование: 14.07.2010
  7. Offline

    VBA Недавно здесь

    Регистрация:
    01.12.2009
    Сообщения:
    5
    Симпатии:
    0
    Пол:
    Мужской
    Подскажите пожалуйста как в этом ватермарке сделать его по центру а не справа снизу? 8|

     
  8. woojin
    Offline

    woojin Местный Команда форума => Cпециалист <=

    Регистрация:
    31.05.2009
    Сообщения:
    3 206
    Симпатии:
    334
    Пол:
    Мужской
    из этого следует, что в параметрах (по умолчанию) функции написано от низа отступ 5 пикселей и от правого края то же 5 пикселей

    внимательнее смотри в код!!!!!!
     
  9. Offline

    VBA Недавно здесь

    Регистрация:
    01.12.2009
    Сообщения:
    5
    Симпатии:
    0
    Пол:
    Мужской
    Я это и сам вижу. Человек который бы знал ответ - написал бы. Не флудите пожалуйста.
     
  10. woojin
    Offline

    woojin Местный Команда форума => Cпециалист <=

    Регистрация:
    31.05.2009
    Сообщения:
    3 206
    Симпатии:
    334
    Пол:
    Мужской
    да не вопрос, мне что жалко что ли :spiteful::
    Оффтопик (не в тему) - жми сюда!
     
  11. Offline

    VBA Недавно здесь

    Регистрация:
    01.12.2009
    Сообщения:
    5
    Симпатии:
    0
    Пол:
    Мужской
    up[!] up[!] up[!] up[!]
    Вот скрипт.
    Для того чтобы установить необходимо залить папку watermark в корень сайта а файл .htaccess в папку с изображениями на которые вы хотите чтобы накладывался водяной знак.
    Кто знает как сделать его по центру?
     

    Вложения:

    • wm.zip
      Размер файла:
      2.2 КБ
      Просмотров:
      28
    Последнее редактирование: 29.09.2010

Поделиться этой страницей

Загрузка...