/**
		 * ImageMagickTool constructor.
		 * @param string $image_path - Path to image
		 */
		function __construct($image_path = null)
		{
			parent::__construct();
			
			$this->SizeCoefficient = 1;
			
			if ($image_path != null)
				$this->LoadImage($image_path);
		}
 public function sendFile()
 {
     if (!is_file($this->source) or !is_readable($this->source)) {
         $this->sendError(404, 'could not find this attachment.');
     }
     // Пытаемся открыть файл на чтение.  Сработает только если файл является картинкой.
     $img = ImageMagick::getInstance();
     $rc = $img->open($this->source, $this->node->filetype);
     // Если не удалось открыть, значит файл не является картинкой.  Отдаём его в режиме скачивания.
     if ($rc === false) {
         return $this->sendFileDownload($img);
     }
     if (!is_file($this->output) or filemtime($this->source) > filemtime($this->output)) {
         // Если файл существует -- обязательно его удаляем, иначе есть
         // шанс запороть оригинал, попытавшись перезаписать симлинк (по
         // причине кривой обработки параметров, или по другой -- не важно,
         // всякое бывает).
         // Масштабируем картинку, если это нужно.
         if ($this->options !== null) {
             $this->processImage($img);
         }
         if (is_link($this->output) and !unlink($this->output)) {
             $this->sendError(500, 'could not remove the file from cache. Overwriting that file would cause the original data to be lost.');
         }
     }
     // Бывают ситуации, когда картинку не нужно отдавать в браузер,
     // чтобы не заставлять клиента грузить ненужные килобайты, а то и мегабайты.
     if (false == $this->options['noshow']) {
         // Открываем файл на чтение.
         $f = fopen($this->output, 'r') or $this->sendError(500, "could not read from cache.");
         // Отправляем файл клиенту.
         header('Content-Type: ' . $img->getType());
         header('Content-Length: ' . filesize($this->output));
         fpassthru($f);
     } else {
         exit;
     }
 }
Beispiel #3
0
 /**
  * Raw arguments directly to ImageMagick
  *
  * @param string $arguments
  *            Arguments
  * @param boolean $input
  *            Defaults to an input option, use false to use it as an output option
  *
  * @return Composite
  * @see ImageMagick::raw()
  */
 public function raw($arguments, $input = true)
 {
     parent::raw($arguments, $input);
     return $this;
 }
Beispiel #4
0
    ImageMagick::addBorder(TEXT_TOOL_TEXT_PATH . $textImages['str1'], 3);
    ImageMagick::addBorder(TEXT_TOOL_TEXT_PATH . $textImages['str2'], 3);
    ImageMagick::addBorder(TEXT_TOOL_TEXT_PATH . $textImages['str3'], 3);
    $feedbackImageName = md5($feedback['CommentText'] . time()) . '.png';
    $path = TEXT_TOOL_TMP_PATH . $feedbackImageName;
    ImageMagick::glueImagesVer(array(TEXT_TOOL_TEXT_PATH . $textImages['str1'], TEXT_TOOL_TEXT_PATH . $textImages['str2'], TEXT_TOOL_TEXT_PATH . $textImages['str3']), $path);
    ImageMagick::addBorder($path, 5);
    $feedbackImages[] = TEXT_TOOL_TMP_PATH . $feedbackImageName;
    if (count($feedbackImages) == $fbNumber) {
        break;
    }
}
$feedbacksImageName = md5(rand(0, 100000) . time()) . '.png';
$path = TEXT_TOOL_TMP_PATH . $feedbacksImageName;
ImageMagick::glueImagesVer($feedbackImages, $path);
ImageMagick::addBorder($path, 5);
?>
<img src="tmp/<?php 
echo $feedbacksImageName;
?>
" width="500px">
<br>
Send image to Social Networks:
<br>
<form method="GET" action="send.php">
    <input type="hidden" name="file" value="<?php 
echo $feedbacksImageName;
?>
">
    <?php 
if (isset($_SESSION['fbid'])) {
Beispiel #5
0
function showConfig()
{
    global $rsgConfig;
    $langs = array();
    //$imageLib   = array();
    $lists = array();
    // PRE-PROCESS SOME LISTS
    // -- Languages --
    /*
        if ($handle = opendir( JPATH_RSGALLERY2_ADMIN.'/language/' )) {
            $i=0;
            while (false !== ($file = readdir( $handle ))) {
                if (!strcasecmp(substr($file,-4),".php") && $file <> "." && $file <> ".." && strcasecmp(substr($file,-11),".ignore.php")) {
                    //$langs[] = mosHTML::makeOption( substr($file,0,-4) );
                }
            }
        }
        
    
        // sort list of languages
        sort( $langs );
        reset( $langs );
    */
    /**
     * detect available graphics libraries
     * @todo call imgUtils graphics lib detection when it is built
     */
    $graphicsLib = array();
    $result = GD2::detect();
    if ($result) {
        $graphicsLib[] = JHTML::_("select.option", 'gd2', $result);
    } else {
        $graphicsLib[] = JHTML::_("select.option", 'gd2', JText::_('GD2 not detected'));
    }
    $result = ImageMagick::detect();
    if ($result) {
        $graphicsLib[] = JHTML::_("select.option", 'imagemagick', $result);
    } else {
        $graphicsLib[] = JHTML::_("select.option", 'imagemagick', JText::_('ImageMagick not detected'));
    }
    $result = Netpbm::detect();
    if ($result) {
        $graphicsLib[] = JHTML::_("select.option", 'netpbm', $result);
    } else {
        $graphicsLib[] = JHTML::_("select.option", 'netpbm', JText::_('netPBM not detected'));
    }
    $lists['graphicsLib'] = JHTML::_("select.genericlist", $graphicsLib, 'graphicsLib', '', 'value', 'text', $rsgConfig->graphicsLib);
    html_rsg2_config::showconfig($lists);
}
Beispiel #6
0
 public function gen()
 {
     if (!$this->image->exists()) {
         throw new \System\Error\File('Cannot generate image thumb. It is not located on filesystem.', $this->image->to_object(), $this->get_path());
     }
     if (extension_loaded('imagemagick')) {
         $im = new ImageMagick($this->get_path(true));
         $im->resampleImage($this->width, $this->height);
         $im->writeImage(BASE_DIR . $this->get_path($this->width, $this->height, $this->crop));
     } else {
         self::gen_gd($this);
     }
     return $this;
 }
Beispiel #7
0
 /**
  * Обработка файла.
  */
 public static function transform(FileNode $node)
 {
     if (0 !== strpos($node->filetype, 'image/')) {
         return;
     }
     $result = array();
     // Относительный путь к исходному файлу
     $source = $node->getRealURL();
     // Путь к файловому хранилищу, используется только чтобы
     // из полного пути сделать относительный после трансформации.
     $storage = Context::last()->config->getPath('modules/files/storage', 'files');
     // Файлы без расширений не обрабатываем, чтобы не нагенерировать каких-нибудь странных имён.
     /*
     if (!($ext = os::getFileExtension($source)))
       return;
     */
     // Правила перевода расширений в типы.
     $typemap = array('png' => 'image/png', 'jpg' => 'image/jpeg');
     foreach (Context::last()->config->getArray(self::confroot) as $name => $settings) {
         if (empty($ext)) {
             $target = $source . '.' . $name . '.' . $settings['format'];
         } else {
             $target = substr($source, 0, -strlen($ext)) . $name . '.' . $settings['format'];
         }
         if (file_exists($target)) {
             unlink($target);
         }
         $im = ImageMagick::getInstance();
         if ($im->open($source, $node->filetype)) {
             $options = array('downsize' => $settings['scalemode'] != 'crop', 'crop' => $settings['scalemode'] == 'crop', 'quality' => intval($settings['quality']));
             if ($im->scale($settings['width'], $settings['height'], $options)) {
                 if ($im->save($target, $typemap[$settings['format']])) {
                     $tmp = array('width' => $im->getWidth(), 'height' => $im->getHeight(), 'filename' => substr($target, strlen($storage) + 1), 'filesize' => filesize($target));
                     $result[$name] = $tmp;
                 }
             }
         }
     }
     return $result;
 }
 function import($PARAM_ARRAY, $vFile)
 {
     // TODO: Check if it in use Danil !!!!
     global $useimagemagick, $imagemagickinstalldir;
     #echo $useimagemagick.'<br>'.$imagemagickinstalldir;
     #exit;
     include_once $GLOBALS['site_class_path'] . "imagemagick.class.php";
     $target_dir = $PARAM_ARRAY['TARGET_DIR'];
     $temp_gallery = "";
     if ($temp_gallery == '') {
         $temp_gallery = $target_dir;
     }
     # print_r($temp_gallery); exit;
     /* from vimal chauhan --- (chets)
     		 $temp=strlen($temp_gallery);
     		 $temp_gallery=substr($temp_gallery,0,$temp-1);
     		 */
     $useimagemagick = "Yes";
     if ($useimagemagick == "Yes") {
         $imObj = new ImageMagick($imagemagickinstalldir, $temp_gallery);
         $imObj->setTargetdir($target_dir);
     }
     $count = 0;
     $idx = 0;
     foreach ($vFile as $file) {
         if ($useimagemagick == "Yes") {
             $imObj->loadByFileData($file);
             $imObj->setVerbose(FALSE);
             $size = $imObj->GetSize();
         } else {
             $size = GetImageSize($file['tmp_name']);
         }
         $HEIGHT = array();
         $WIDTH = array();
         $PERFIX = array();
         for ($i = 1; $i < count($PARAM_ARRAY); $i++) {
             $height_width = $PARAM_ARRAY[$i - 1]['WIDTH_HEIGHT'];
             $height_width = explode("X", $height_width);
             $WIDTH[$i] = $height_width[0];
             $HEIGHT[$i] = $height_width[1];
             $PERFIX[$i] = $PARAM_ARRAY[$i - 1]['PREFIX'];
         }
         $time = time();
         if ($useimagemagick == "Yes") {
             for ($i = 1; $i < count($PARAM_ARRAY); $i++) {
                 if ($PERFIX[$i] != '') {
                     $temp = $PERFIX[$i] . "_" . $time;
                 } else {
                     $temp = $time;
                 }
                 if ($WIDTH[$i] > 0 && $HEIGHT[$i] > 0) {
                     $imObj->loadByFileData($file);
                     $imObj->Resize($WIDTH[$i], $HEIGHT[$i], 1);
                     list($WIDTH[$i], $HEIGHT[$i]) = $imObj->GetSize();
                     $filename[$i] = $imObj->Save($temp);
                 } else {
                     $filename1 = $target_dir . "/" . $temp . basename($file['name']);
                     copy($file['tmp_name'], $filename1);
                     $filename[$i] = $temp . basename($file['name']);
                 }
             }
             $imObj->CleanUp();
             $fname = substr($filename[1], strlen($PERFIX[$i]));
             $ReturnFile[$idx] = $fname;
         } else {
             for ($i = 1; $i < count($PARAM_ARRAY); $i++) {
                 if ($PERFIX[$i] != '') {
                     $temp = $PERFIX[$i] . "_" . $time;
                 } else {
                     $temp = $time;
                 }
                 $filename1 = $target_dir . "/" . $temp . basename($file['name']);
                 #echo $filename1;
                 #exit;
                 copy($file['tmp_name'], $filename1);
             }
             $ReturnFile[$idx] = $time . basename($file['name']);
         }
         $idx++;
     }
     return $ReturnFile;
 }
 /**
  * Alias for 'valid'. Required as a workaround for the fact that
  * error messages keys in Kohana's Validation library only use the
  * method name, not class name plus method name. This means that
  * there is no way to define different error messages for e.g.,
  * upload::valid and ImageMagick::valid.
  *
  * @param   mixed   filename, or array of uploaded file details
  * @return  bool
  */
 public static function imagemagick_valid($file)
 {
     return ImageMagick::valid($file);
 }
Beispiel #10
0
 /**
  * generic image resize function
  * @param string full path of source image
  * @param string full path of target image
  * @param int width of target
  * @return true if successfull, false if error
  * @todo only writes in JPEG, this should be given as a user option
  */
 function resizeImage($source, $target, $targetWidth)
 {
     global $rsgConfig;
     switch ($rsgConfig->get('graphicsLib')) {
         case 'gd2':
             return GD2::resizeImage($source, $target, $targetWidth);
             break;
         case 'imagemagick':
             return ImageMagick::resizeImage($source, $target, $targetWidth);
             break;
         case 'netpbm':
             return Netpbm::resizeImage($source, $target, $targetWidth);
             break;
         default:
             JError::raiseNotice('ERROR_CODE', JText::_('INVALID GRAPHICS LIBRARY') . $rsgConfig->get('graphicsLib'));
             return false;
     }
 }