getHeight() public method

public getHeight ( )
Example #1
0
 function addTag($srcPath, $dstPath)
 {
     $srcImage = new Image($srcPath);
     $tagImagePath = CODE_ROOT_DIR . "uploads/custom/" . Config::get("watermarkImageSrc");
     if (!file_exists($tagImagePath)) {
         return;
     }
     $tagImage = new Image($tagImagePath);
     list($posV, $posH) = explode(",", Config::get("imageWatermarkPosition"));
     $tagMarginH = 5;
     $tagMarginV = 5;
     if ($posH == "l") {
         $tagPositionX = 0 + $tagMarginH;
     } else {
         $tagPositionX = max($srcImage->getWidth() - $tagImage->getWidth() - $tagMarginH, 0);
     }
     if ($posV == "t") {
         $tagPositionY = 0 + $tagMarginV;
     } else {
         $tagPositionY = max($srcImage->getHeight() - $tagImage->getHeight() - $tagMarginV, 0);
     }
     imagecopyresampled($srcImage->im, $tagImage->im, $tagPositionX, $tagPositionY, 0, 0, $tagImage->getWidth(), $tagImage->getHeight(), $tagImage->getWidth(), $tagImage->getHeight());
     $srcImage->setPath($dstPath);
     $srcImage->saveToFile();
 }
		static public function imageResize($fname,$width,$height) {
			$i = new Image( $fname );
			$owhr=$i->getWidth()/$i->getHeight();
			$twhr=$width/$height;
			if( $owhr==$twhr )	{
				$i->resize( $width,$height );
			}	elseif( $owhr>$twhr )	{
				$i->resizeToHeight( $height );
				$i->crop( ($i->getWidth()-$width)/2, 0, $width, $height);
			}	else	{
				$i->resizeToWidth( $width );
				$i->crop( 0, ($i->getHeight()-$height)/2, $width, $height);
			}
			$i->save();
		}
Example #3
0
 public function readFolder()
 {
     $folder = $this->customer->getFolderName();
     $dir = DIR_IMAGE . "catalog/" . $folder;
     $allfiles = scandir($dir);
     $img_links = array();
     $counting = 0;
     foreach ($allfiles as $image) {
         //if the file is not hidden get the the URI
         if (substr($image, 0, 1) != '.') {
             //Once we get certified the config.php needs to be modified.
             $modify_image = new Image(DIR_IMAGE . "catalog/" . $folder . "/" . $image);
             // $mark = new Image(DIR_IMAGE. "logo.png");
             $width = $modify_image->getWidth() * 0.2;
             $height = $modify_image->getHeight() * 0.2;
             // $mark->resize($width, $height);
             // $modify_image->watermark($mark);
             $size = $width * $height;
             $modify_image->save($modify_image->getFile());
             $img_links[$counting]['source'] = HTTPS_SERVER . "/image/catalog/" . $folder . "/" . $image;
             $img_links[$counting]['width'] = $modify_image->getWidth();
             $img_links[$counting]['height'] = $modify_image->getHeight();
             $counting++;
         }
     }
     return $img_links;
 }
Example #4
0
 /**
  * @param string $filename
  * @param int $width
  * @param int $height
  * @return string
  */
 public function resize($filename, $width, $height)
 {
     if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
         return null;
     }
     $info = pathinfo($filename);
     $extension = $info['extension'];
     $old_image = $filename;
     try {
         $image = new Image(DIR_IMAGE . $old_image);
     } catch (Exception $exc) {
         $image = new Image(DIR_IMAGE . 'no_image.jpg');
     }
     /// Ensure target size doesn't exceed original size
     $ratio = $image->getWidth() / $image->getHeight();
     $expectedHeight = round($width / $ratio);
     $expectedWidth = round($height * $ratio);
     if ($image->getWidth() >= $width) {
         $targetWidth = $width;
         $targetHeight = $expectedHeight;
     } else {
         $targetWidth = $image->getWidth();
         $targetHeight = $image->getHeight();
     }
     if ($image->getHeight() < $targetHeight) {
         $targetWidth = $expectedWidth;
         $targetHeight = $image->getHeight();
     }
     $new_image = 'cache/' . substr($filename, 0, strrpos($filename, '.')) . '-' . $targetWidth . 'x' . $targetHeight . '.' . $extension;
     if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $new_image)));
         foreach ($directories as $directory) {
             $path = $path . '/' . $directory;
             if (!file_exists(DIR_IMAGE . $path)) {
                 @mkdir(DIR_IMAGE . $path, 0777);
             }
         }
         $image->resize($targetWidth, $targetHeight);
         $image->save(DIR_IMAGE . $new_image);
     }
     if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
         return HTTPS_IMAGE . $new_image;
     } else {
         return HTTP_IMAGE . $new_image;
     }
 }
 /**
  * Resizes image by width or height only if the source image is bigger than the given width/height.
  * This prevents ugly upscaling.
  *
  * @param int  $width [optional]
  * @param int  $height [optional]
  * @param bool $upscale [optional]
  *
  * @return Image
  */
 public function getImageAt($width = null, $height = null, $upscale = false)
 {
     if (!$this->owner->exists()) {
         return $this->owner;
     }
     $realWidth = $this->owner->getWidth();
     $realHeight = $this->owner->getHeight();
     if ($width && $height) {
         return $realWidth < $width && $realHeight < $height && !$upscale ? $this->owner : $this->owner->Fit($width, $height);
     } else {
         if ($width) {
             return $realWidth < $width && !$upscale ? $this->owner : $this->owner->ScaleWidth($width);
         } else {
             return $realHeight < $height && !$upscale ? $this->owner : $this->owner->ScaleHeight($height);
         }
     }
 }
Example #6
0
 /**
  * Sets the objects properties
  *
  * @param $percentage float The percentage that the merge image should take up.
  */
 protected function setProperties($percentage)
 {
     if ($percentage > 1) {
         throw new \InvalidArgumentException('$percentage must be less than 1');
     }
     $this->sourceImageHeight = $this->sourceImage->getHeight();
     $this->sourceImageWidth = $this->sourceImage->getWidth();
     $this->mergeImageHeight = $this->mergeImage->getHeight();
     $this->mergeImageWidth = $this->mergeImage->getWidth();
     $this->calculateOverlap($percentage);
     $this->calculateCenter();
 }
Example #7
0
 /**
  * Sets the objects properties
  *
  * @param $percentage float The percentage that the merge image should take up.
  */
 protected function setProperties($percentage)
 {
     if ($percentage > 1) {
         throw new \InvalidArgumentException('$percentage must be less than 1');
     }
     $this->sourceHeight = $this->sourceImage->getHeight();
     $this->sourceWidth = $this->sourceImage->getWidth();
     $this->mergeHeight = $this->mergeImage->getHeight();
     $this->mergeWidth = $this->mergeImage->getWidth();
     $this->postMergeHeight = $this->mergeHeight * $percentage;
     $this->postMergeWidth = $this->mergeWidth * $percentage;
     $this->mergePosHeight = $this->sourceHeight / 2 - $this->postMergeHeight / 2;
     $this->mergePosWidth = $this->sourceWidth / 2 - $this->postMergeHeight / 2;
 }
Example #8
0
 /**
  * handle overview request
  */
 private function handleOverview()
 {
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $page = $this->getPage();
     $this->pagerUrl->setParameter($view->getUrlId(), $view->getType());
     $taglist = $this->plugin->getTagList(array('plugin_type' => News::TYPE_ARCHIVE));
     if (!$taglist) {
         return;
     }
     $tree = $this->director->tree;
     $url = new Url(true);
     $url->setParameter($view->getUrlId(), News::VIEW_DETAIL);
     // link to news tree nodes
     $treeRef = new NewsTreeRef();
     foreach ($taglist as $item) {
         $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
         $template->setPostfix($item['tag']);
         $template->setCacheable(true);
         // check if template is in cache
         if (!$template->isCached()) {
             // get settings
             $settings = $this->getSettings();
             $key = array('tree_id' => $item['tree_id'], 'tag' => $item['tag']);
             $detail = $this->getDetail($key);
             $treeRefList = $treeRef->getList($key);
             $treeItemList = array();
             foreach ($treeRefList['data'] as $treeRefItem) {
                 if (!$tree->exists($treeRefItem['ref_tree_id'])) {
                     continue;
                 }
                 $treeItemList[] = $treeRefItem['ref_tree_id'];
             }
             if (!$treeItemList) {
                 continue;
             }
             $searchcriteria = array('tree_id' => $treeItemList, 'active' => true);
             if ($detail['online']) {
                 $searchcriteria['archiveonline'] = $detail['online'];
             }
             $searchcriteria['archiveoffline'] = $detail['offline'] ? $detail['offline'] : time();
             $overview = $this->getNewsOverview();
             $list = $overview->getList($searchcriteria, $settings['rows'], $page);
             foreach ($list['data'] as &$newsitem) {
                 $url->setParameter('id', $newsitem['id']);
                 $newsitem['href_detail'] = $url->getUrl(true);
                 if ($newsitem['thumbnail']) {
                     $img = new Image($newsitem['thumbnail'], $this->plugin->getContentPath(true));
                     $newsitem['thumbnail'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
                 }
             }
             $template->setVariable('news', $list);
             $template->setVariable('display', $settings['display'], false);
         }
         $this->template[$item['tag']] = $template;
     }
 }
Example #9
0
 /**
  * Create a new image based on an image preset.
  *
  * @param array $actions An image preset array.
  * @param Image $image Path of the source file.
  * @param string $dst Path of the destination file.
  * @throws \RuntimeException
  * @return Image
  */
 protected function buildImage($actions, Image $image, $dst)
 {
     foreach ($actions as $action) {
         // Make sure the width and height are computed first so they can be used
         // in relative x/yoffsets like 'center' or 'bottom'.
         if (isset($action['width'])) {
             $action['width'] = $this->percent($action['width'], $image->getWidth());
         }
         if (isset($action['height'])) {
             $action['height'] = $this->percent($action['height'], $image->getHeight());
         }
         if (isset($action['xoffset'])) {
             $action['xoffset'] = $this->keywords($action['xoffset'], $image->getWidth(), $action['width']);
         }
         if (isset($action['yoffset'])) {
             $action['yoffset'] = $this->keywords($action['yoffset'], $image->getHeight(), $action['height']);
         }
         $this->getMethodCaller()->call($image, $action['action'], $action);
     }
     return $image->save($dst);
 }
Example #10
0
 /**
  * handle tree edit
  */
 private function handleTreeEditGet($retrieveFields = true)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $view->setType(Calendar::VIEW_IMAGE_EDIT);
     $tree_id = intval($request->getValue('tree_id'));
     $tag = $request->getValue('tag');
     $template->setVariable('tree_id', $tree_id, false);
     $template->setVariable('tag', $tag, false);
     if (!$request->exists('id')) {
         throw new Exception('Bestand is missing.');
     }
     $id = intval($request->getValue('id'));
     $template->setVariable('id', $id, false);
     $key = array('id' => $id);
     if ($retrieveFields) {
         $fields = $this->getDetail($key);
     } else {
         $fields = $this->getFields(SqlParser::MOD_UPDATE);
         $detail = $this->getDetail($key);
         $fields['file'] = $detail['file'];
     }
     $this->setFields($fields);
     if ($fields['image']) {
         $img = new Image($fields['image'], $this->plugin->getContentPath(true));
         $fields['image'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
     }
     $template->setVariable($fields);
     $this->handleTreeSettings($template);
     // get crop settings
     $settings = $this->plugin->getSettings();
     //only crop if both width and height defaults are set
     if ($fields['image'] && $settings['image_width'] && $settings['image_height'] && ($fields['image']['width'] > $settings['image_width'] || $fields['image']['height'] > $settings['image_height'])) {
         $theme = $this->director->theme;
         $parseFile = new ParseFile();
         $parseFile->setVariable($fields);
         $parseFile->setVariable('imgTag', 'imgsrc');
         $parseFile->setVariable($settings);
         $parseFile->setSource($this->plugin->getHtdocsPath(true) . "js/cropinit.js.in");
         //$parseFile->setDestination($this->plugin->getCachePath(true)."cropinit_tpl_content.js");
         //$parseFile->save();
         $theme->addJavascript($parseFile->fetch());
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/prototype.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/scriptaculous.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/cropper.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/mint.js"></script>');
         //$theme->addHeader('<script type="text/javascript" src="'.$this->plugin->getCachePath().'cropinit_tpl_content.js"></script>');
     }
     $this->template[$this->director->theme->getConfig()->main_tag] = $template;
 }
Example #11
0
 private function handlePluginList($tag, $parameters)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $searchcriteria = isset($parameters) && array_key_exists('searchcriteria', $parameters) ? $parameters['searchcriteria'] : array();
     $keys = isset($parameters) && array_key_exists('keys', $parameters) ? $parameters['keys'] : array();
     $searchcriteria['id'] = $keys;
     $settings = $this->plugin->getSettings();
     $template->setVariable('settings', $settings);
     $systemSite = new SystemSite();
     $tree = $systemSite->getTree();
     $list = $this->getList($searchcriteria, $pagesize, $page);
     foreach ($list['data'] as &$item) {
         //TODO get url from caller plugin (newsletter) to track visits
         $url = new Url();
         $url->setPath($request->getProtocol() . $request->getDomain() . $tree->getPath($item['tree_id']));
         $url->setParameter('id', $item['id']);
         $url->setParameter(ViewManager::URL_KEY_DEFAULT, Calendar::VIEW_DETAIL);
         $item['href_detail'] = $url->getUrl(true);
         if ($item['thumbnail']) {
             $img = new Image($item['thumbnail'], $this->plugin->getContentPath(true));
             $item['thumbnail'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
         }
     }
     $template->setVariable('calendar', $list);
     $this->template[$tag] = $template;
 }
Example #12
0
 public function insert(Image $replacement, $x, $y, $width, $height)
 {
     imagecopyresized($this->handle, $replacement->getHandle(), $x, $y, 0, 0, $width, $height, $replacement->getWidth(), $replacement->getHeight());
     return $this;
 }
Example #13
0
 protected function formatImage($image, $inCitation = false)
 {
     $filename = (string) $image['filename'];
     if (!$filename) {
         return '';
     }
     $caption = (string) $image['caption'];
     $iconWidth = SearchForm::THUMB_WIDTH;
     $iconHeight = 48;
     $t = Title::makeTitle(NS_IMAGE, $filename);
     if (!$t || !$t->exists()) {
         return '';
     }
     $image = new Image($t);
     $maxHoverWidth = 700;
     $maxHoverHeight = 300;
     $width = $image->getWidth();
     $height = $image->getHeight();
     if ($height > 0 && $maxHoverWidth > $width * $maxHoverHeight / $height) {
         $maxHoverWidth = wfFitBoxWidth($width, $height, $maxHoverHeight);
     }
     $imageURL = $image->createThumb($maxHoverWidth, $maxHoverHeight);
     $titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxHoverWidth}");
     if ($inCitation) {
         return "<span class=\"wr-citation-image wr-imagehover inline-block\" title=\"{$titleAttr}\">{$caption} [[Image:{$filename}|{$iconWidth}x{$iconHeight}px]]</span>";
     } else {
         return "<span class=\"wr-imagehover inline-block\"  title=\"{$titleAttr}\">[[Image:{$filename}|thumb|left|{$caption}]]</span>";
     }
     //      return <<<END
     //<div class="inline-block">
     //   <span id="$id">[[Image:$filename|thumb|left|$id. $caption]]</span>
     //</div>
     //END;
 }
 /**
  * @param Image $src
  * @param int $x
  * @param int $y
  * @param int $width
  * @param int $height
  * @return Image
  */
 public function addAndResizeLayer(Image $src, $x, $y, $width, $height)
 {
     if ($src->getWidth() !== $width || $src->getHeight() !== $height) {
         $src = $src->resizeTo($width, $height);
     }
     return $this->addLayer($src, $x, $y);
 }
Example #15
0
 public function uploadAll()
 {
     $this->load->language('common/filemanager');
     $error = array();
     $extension = array("jpeg", "jpg", "png", "gif", "JPG", "bmp");
     // Make sure we have the correct directory
     if (isset($this->request->get['directory'])) {
         $directory = rtrim(DIR_IMAGE . 'catalog/' . str_replace(array('../', '..\\', '..'), '', $this->request->get['directory']), '/');
     } else {
         $directory = DIR_IMAGE . 'catalog';
     }
     // Check it's a directory
     if (!is_dir($directory)) {
         $json['error'] = $this->language->get('error_directory');
     }
     $clientFolder = $this->request->get['directory'];
     foreach ($this->request->files["file"]["tmp_name"] as $key => $tmp_name) {
         $file_name = $this->request->files["file"]["name"][$key];
         $file_name = str_replace(" ", "_", $file_name);
         $file_tmp = $this->request->files["file"]["tmp_name"][$key];
         $ext = pathinfo($file_name, PATHINFO_EXTENSION);
         //Contruct the image object for modification
         $new_image = new Image($file_tmp);
         $w = $new_image->getWidth();
         $h = $new_image->getHeight();
         $size = $w * $h;
         $new_image->resize($w * 0.5, $h * 0.5);
         if (in_array($ext, $extension)) {
             if (!file_exists($directory . "/" . $file_name)) {
                 //move_uploaded_file($file_tmp = $this->request->files["file"]["tmp_name"][$key], $directory . "/" . $file_name);
                 move_uploaded_file($new_image->getFile(), $directory . "/" . $file_name);
                 $json['success'] = 'Files are uploaded';
             } else {
                 $json['error'] = 'Duplicate file error';
             }
         } else {
             array_push($error, "{$file_name}, ");
             $json['error'] = $this->language->get('error_upload');
         }
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }
Example #16
0
 /**
  * Puts another image into this image.
  * @param  Image
  * @param  mixed  x-coordinate in pixels or percent
  * @param  mixed  y-coordinate in pixels or percent
  * @param  int  opacity 0..100
  * @return Image  provides a fluent interface
  */
 public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
 {
     $opacity = max(0, min(100, (int) $opacity));
     if (substr($left, -1) === '%') {
         $left = round(($this->getWidth() - $image->getWidth()) / 100 * $left);
     }
     if (substr($top, -1) === '%') {
         $top = round(($this->getHeight() - $image->getHeight()) / 100 * $top);
     }
     if ($opacity === 100) {
         imagecopy($this->getImageResource(), $image->getImageResource(), $left, $top, 0, 0, $image->getWidth(), $image->getHeight());
     } elseif ($opacity != 0) {
         imagecopymerge($this->getImageResource(), $image->getImageResource(), $left, $top, 0, 0, $image->getWidth(), $image->getHeight(), $opacity);
     }
     return $this;
 }
Example #17
0
 /**
  * page for upload face in iframe
  * override the js array
  */
 public function ajax_face()
 {
     if (!$this->RequestHandler->isPost()) {
         $this->error(ECode::$SYS_REQUESTERROR);
     }
     $this->requestLogin();
     $u = User::getInstance();
     $face = Configure::read("user.face");
     //init upload file
     if (isset($this->params['url']['name'])) {
         //html5 mode
         $tmp_name = tempnam(CACHE, "upload_");
         file_put_contents($tmp_name, file_get_contents('php://input'));
         $file = array('tmp_name' => $tmp_name, 'name' => nforum_iconv('utf-8', $this->encoding, $this->params['url']['name']), 'size' => filesize($tmp_name), 'error' => 0);
     } else {
         if (isset($this->params['form']['file']) && is_array($this->params['form']['file'])) {
             //flash mode
             $file = $this->params['form']['file'];
             $file['name'] = nforum_iconv('utf-8', $this->encoding, $file['name']);
         } else {
             $this->error(ECode::$ATT_NONE);
         }
     }
     $errno = isset($file['error']) ? $file['error'] : UPLOAD_ERR_NO_FILE;
     switch ($errno) {
         case UPLOAD_ERR_OK:
             $tmpFile = $file['tmp_name'];
             $tmpName = $file['name'];
             if (!isset($tmp_name) && !is_uploaded_file($tmpFile)) {
                 $msg = "上传错误";
                 break;
             }
             $ext = strrchr($tmpName, '.');
             if (!in_array(strtolower($ext), $face['ext'])) {
                 $msg = "上传文件扩展名有误";
                 break;
             }
             if (filesize($tmpFile) > $face['size']) {
                 $msg = "文件大小超过上限" . $face['size'] / 1024 . "K";
                 break;
             }
             mt_srand();
             $faceDir = $face['dir'] . DS . strtoupper(substr($u->userid, 0, 1));
             $facePath = $faceDir . DS . $u->userid . "." . mt_rand(0, 10000) . $ext;
             $faceFullDir = WWW_ROOT . $faceDir;
             $faceFullPath = WWW_ROOT . $facePath;
             if (!is_dir($faceFullDir)) {
                 @mkdir($faceFullDir);
             }
             if (is_file($faceFullPath)) {
                 $msg = "我觉得您今天可以买彩票了";
                 break;
             }
             if (isset($tmp_name)) {
                 if (!rename($tmp_name, $faceFullPath)) {
                     $msg = "上传错误";
                     break;
                 }
             } else {
                 if (!move_uploaded_file($tmpFile, $faceFullPath)) {
                     $msg = "上传错误";
                     break;
                 }
             }
             App::import('vendor', "inc/image");
             try {
                 $img = new Image($faceFullPath);
                 $format = $img->getFormat();
                 if (!in_array($format, range(1, 3))) {
                     $msg = "上传的文件貌似不是图像文件";
                     break;
                 }
                 //gif do not thumbnail
                 if ($format != 1) {
                     $facePath = preg_replace("/\\.[^.]+\$/", '.jpg', $facePath);
                     $faceFullPath = WWW_ROOT . $facePath;
                     $img->thumbnail($faceFullPath, 120, 120);
                 }
             } catch (ImageNullException $e) {
                 $msg = "上传的文件貌似不是图像文件";
                 break;
             }
             $this->set("no_html_data", array("img" => $facePath, "width" => $img->getWidth(), "height" => $img->getHeight(), "ajax_st" => 1, "ajax_code" => ECode::$SYS_AJAXOK, "ajax_msg" => "文件上传成功"));
             return;
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $msg = "文件大小超过系统上限";
             break;
         case UPLOAD_ERR_PARTIAL:
             $msg = "文件传输出错!";
             break;
         case UPLOAD_ERR_NO_FILE:
             $msg = "没有文件上传!";
             break;
         default:
             $msg = "未知错误";
     }
     if (isset($tmp_name)) {
         @unlink($tmp_name);
     }
     $this->set("no_html_data", array("ajax_st" => 0, "ajax_code" => ECode::$SYS_AJAXERROR, "ajax_msg" => $msg));
 }
Example #18
0
 /**
  * Make HTML for a thumbnail including image, border and caption
  * $img is an Image object
  */
 function makeThumbLinkObj($img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight = false, $framed = false, $manual_thumb = "")
 {
     global $wgStylePath, $wgContLang;
     $url = $img->getViewURL();
     $width = $height = 0;
     if ($img->exists()) {
         $width = $img->getWidth();
         $height = $img->getHeight();
     }
     if (0 == $width || 0 == $height) {
         $width = $height = 200;
     }
     if ($boxwidth == 0) {
         $boxwidth = 200;
     }
     if ($framed) {
         // Use image dimensions, don't scale
         $boxwidth = $width;
         $oboxwidth = $boxwidth + 2;
         $boxheight = $height;
         $thumbUrl = $url;
     } else {
         $h = intval($height / ($width / $boxwidth));
         $oboxwidth = $boxwidth + 2;
         if (!$boxheight === false && $h > $boxheight) {
             $boxwidth *= $boxheight / $h;
         } else {
             $boxheight = $h;
         }
         if ('' == $manual_thumb) {
             $thumbUrl = $img->createThumb($boxwidth);
         }
     }
     if ($manual_thumb != '') {
         $manual_title = Title::makeTitleSafe(NS_IMAGE, $manual_thumb);
         #new Title ( $manual_thumb ) ;
         $manual_img = new Image($manual_title);
         $thumbUrl = $manual_img->getViewURL();
         if ($manual_img->exists()) {
             $width = $manual_img->getWidth();
             $height = $manual_img->getHeight();
             $boxwidth = $width;
             $boxheight = $height;
             $oboxwidth = $boxwidth + 2;
         }
     }
     $u = $img->getEscapeLocalURL();
     $more = htmlspecialchars(wfMsg('thumbnail-more'));
     $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
     $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
     $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
     if ($thumbUrl == '') {
         $s .= $this->makeBrokenImageLinkObj($img->getTitle());
         $zoomicon = '';
     } else {
         $s .= '<a href="' . $u . '" class="internal" title="' . $alt . '">' . '<img src="' . $thumbUrl . '" alt="' . $alt . '" ' . 'width="' . $boxwidth . '" height="' . $boxheight . '" ' . 'longdesc="' . $u . '" /></a>';
         if ($framed) {
             $zoomicon = "";
         } else {
             $zoomicon = '<div class="magnify" style="float:' . $magnifyalign . '">' . '<a href="' . $u . '" class="internal" title="' . $more . '">' . '<img src="' . $wgStylePath . '/common/images/magnify-clip.png" ' . 'width="15" height="11" alt="' . $more . '" /></a></div>';
         }
     }
     $s .= '  <div class="thumbcaption" ' . $textalign . '>' . $zoomicon . $label . "</div></div></div>";
     return str_replace("\n", ' ', $s);
 }
Example #19
0
File: main.php Project: vench/esee
<?php

namespace esee;

require_once 'esee/App.php';
App::autoload();
$image = new Image('../x1.jpg');
$image->open();
$diff = 16777215 / 2;
$provider = new provider\ProviderFile('data.txt');
$chainBuilder = new ChainBuilder($image, $diff);
$ar = [];
for ($y = 0; $y < $image->getHeight(); $y++) {
    for ($x = 0; $x < $image->getWidth(); $x++) {
        if ($chainBuilder->getValue($x, $y) == 1) {
            $c = $chainBuilder->makeChain($x, $y);
            if (is_null($c)) {
                continue;
            }
            Helper::view2($c);
            list($ax, $ay) = Helper::avg($c);
            $char = $provider->findByXY($ax, $ay);
            if (!is_null($char)) {
                echo "Find: {$char->char}\n";
                exit;
            } else {
                echo "No find: {$ax}, {$ay}\n";
            }
            array_push($ar, $c);
        }
    }
Example #20
0
 /**
  * handle tree edit
  */
 private function handleTreeEditGet($retrieveFields = true)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $view->setType(ViewManager::TREE_EDIT);
     if (!$request->exists('id')) {
         throw new Exception('Link is missing.');
     }
     $id = intval($request->getValue('id'));
     $template->setVariable('id', $id, false);
     $key = array('id' => $id);
     if ($retrieveFields) {
         $fields = $this->getDetail($key);
     } else {
         $fields = $this->getFields(SqlParser::MOD_UPDATE);
         $detail = $this->getDetail($key);
         $fields['image'] = $detail['image'];
     }
     $this->setFields($fields);
     if ($fields['image']) {
         $img = new Image($fields['image'], $this->getContentPath(true));
         $fields['image'] = array('src' => $this->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
     }
     $template->setVariable($fields, NULL, false);
     $this->handleTreeSettings($template);
     $template->setVariable('fckBox', $this->getEditor($fields['text']), false);
     // get all tree nodes which have plugin modules
     $site = new SystemSite();
     $tree = $site->getTree();
     $treelist = $tree->getList();
     foreach ($treelist as &$item) {
         $item['name'] = $tree->toString($item['id'], '/', 'name');
     }
     $template->setVariable('cbo_tree_id', Utils::getHtmlCombo($treelist, $fields['ref_tree_id'], '...'));
     // get crop settings
     $settings = $this->plugin->getObject(Links::TYPE_SETTINGS)->getSettings($fields['tag'], $fields['tree_id']);
     //only crop if both width and height defaults are set
     if ($fields['image'] && $settings['image_width'] && $settings['image_height'] && ($fields['image']['width'] > $settings['image_width'] || $fields['image']['height'] > $settings['image_height'])) {
         $theme = $this->director->theme;
         $parseFile = new ParseFile();
         $parseFile->setVariable($fields, NULL, false);
         $parseFile->setVariable('imgTag', 'imgsrc', false);
         $parseFile->setVariable($settings, NULL, false);
         $parseFile->setSource($this->getHtdocsPath(true) . "js/cropinit.js.in");
         //$parseFile->setDestination($this->getCachePath(true)."cropinit_tpl_content.js");
         //$parseFile->save();
         $theme->addJavascript($parseFile->fetch());
         //$this->headers[] = '<script type="text/javascript" src="'.$this->getCachePath().'cropinit_tpl_content.js"></script>';
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/prototype.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/scriptaculous.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/cropper.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/mint.js"></script>');
     }
     $this->template[$this->director->theme->getConfig()->main_tag] = $template;
 }
Example #21
0
 public function alphaMask(Image $mask)
 {
     $new_img = $this->newImage($this->getWidth(), $this->getHeight());
     // resize the mask if it's not the same size
     if ($mask->getWidth() != $this->getWidth() || $mask->getHeight() != $this->getHeight()) {
         $mask->resize($this->getWidth(), $this->getHeight(), self::RESIZE_BASE_MIN, true);
     }
     // put the mask on
     for ($x = 0; $x < $this->getWidth(); $x++) {
         for ($y = 0; $y < $this->getHeight(); $y++) {
             $alpha = imagecolorsforindex($mask->getHandle(), imagecolorat($mask->getHandle(), $x, $y));
             $alpha = 127 - floor($alpha['red'] / 2);
             $color = imagecolorsforindex($this->getHandle(), imagecolorat($this->getHandle(), $x, $y));
             $new_color = imagecolorallocatealpha($new_img, $color['red'], $color['green'], $color['blue'], $alpha);
             imagesetpixel($new_img, $x, $y, $new_color);
         }
     }
     imagecopy($this->getHandle(), $new_img, 0, 0, 0, 0, $this->getWidth(), $this->getHeight());
     imagedestroy($new_img);
 }
Example #22
0
    /**
     * Blends two images together.
     *
     * @param Image $otherImage Other image to blend.
     * @param Point $position X, Y coordinates of the destination point.
     * @param int $blendingMode Blending mode, for example: Blender::USE_ADDITION [is used as default]
     * @param float $opacity Opacity factor [0...1], used only in the Blender::USE_TRANSPARENCY blending mode
     * @return Image
     */
    public function useBlender(Image $otherImage, Point $position, $blendingMode = Blender::USE_ADDITION, $opacity = null)
    {
        $image = $otherImage->getGd2Handle();
        $mode = Shader::USE_RGB;
        switch ($blendingMode) {
            case Blender::USE_ADDITION:
                $ops = '$r += $r2; $g += $g2; $b += $b2;';
                break;
            case Blender::USE_SUBTRACT:
                $ops = '$r -= $r2; $g -= $g2; $b -= $b2;
				$r = $r < 0 ? 0 : $r;
				$g = $g < 0 ? 0 : $g;
				$b = $b < 0 ? 0 : $b;
				';
                break;
            case Blender::USE_DIVIDE:
                $ops = '
				$r = $r2 / ($r + 0.001);
				$g = $g2 / ($g + 0.001);
				$b = $b2 / ($b + 0.001);
				';
                break;
            case Blender::USE_LIGHTEN:
                $ops = '$luminance2 = ($g2 >= $b2 ? ($r2 >= $g2 ? $r2 : $g2) : ($r2 >= $b2 ? $r2 : $b2));
				$luminance = ($g >= $b ? ($r >= $g ? $r : $g) : ($r >= $b ? $r : $b));
				if($luminance < $luminance2) {
					$r = $r2; $g = $g2; $b = $b2;
				}
				';
                break;
            case Blender::USE_DARKEN:
                $ops = '$luminance2 = ($g2 >= $b2 ? ($r2 >= $g2 ? $r2 : $g2) : ($r2 >= $b2 ? $r2 : $b2));
				$luminance = ($g >= $b ? ($r >= $g ? $r : $g) : ($r >= $b ? $r : $b));
				if($luminance > $luminance2) {
					$r = $r2; $g = $g2; $b = $b2;
				}
				';
                break;
            case Blender::USE_DIFFERENCE:
                $ops = '$r -= $r2; $g -= $g2; $b -= $b2;
				$r = $r < 0 ? -$r : $r;
				$g = $g < 0 ? -$g : $g;
				$b = $b < 0 ? -$b : $b;
				';
                break;
            case Blender::USE_MULTIPLY:
                $ops = '$r *= 255; $g *=255; $b *= 255;
				$r2 *= 255; $g2 *=255; $b2 *= 255;
				$r = ($r * $r2) / 65025;
				$g = ($g * $g2) / 65025;
				$b = ($b * $b2) / 65025;
				';
                break;
            case Blender::USE_OPACITY:
                $alpha = 1 - $opacity;
                $mode = Shader::USE_INT | Shader::USE_ALPHA;
                $ops = '$r = $r2; $g = $g2; $b = $b2; $a = ' . $alpha . ';';
                break;
            default:
                throw new Exception('Unsupported blending mode');
                break;
        }
        $shader = new Shader('
			$rgb2 = imagecolorat($args[0], $x - $args[1], $y - $args[2]);
			$r2 = (($rgb2 >> 16) & 0xff) / 255;
			$g2 = (($rgb2 >> 8) & 0xff) / 255;
			$b2 = ($rgb2 & 0xff) / 255;
			' . $ops);
        $shader->setMode($mode);
        $shader->useArea($position, new Point($otherImage->getWidth() + $position->x, $otherImage->getHeight() + $position->y));
        $this->useShader($shader, array($image, $position->x, $position->y));
        return $this;
    }
Example #23
0
    protected function getImageInfo($image, $firstChildClass = '')
    {
        $imageText = '';
        $thumbWidth = SearchForm::THUMB_WIDTH;
        $filename = (string) $image['filename'];
        $t = Title::makeTitle(NS_IMAGE, $filename);
        if ($t && $t->exists()) {
            $img = new Image($t);
            $caption = (string) $image['caption'];
            if (!$caption) {
                $caption = $filename;
            }
            $maxWidth = 700;
            $maxHeight = 300;
            $width = $img->getWidth();
            $height = $img->getHeight();
            if ($maxWidth > $width * $maxHeight / $height) {
                $maxWidth = wfFitBoxWidth($width, $height, $maxHeight);
            }
            $imageURL = $img->createThumb($maxWidth, $maxHeight);
            $caption = str_replace('|', ' ', $caption);
            $titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxWidth}|{$caption}");
            $imageText = <<<END
<td style="width: 1%" class="{$firstChildClass}">
   <div class="wr-infobox-image wr-imagehover" title="{$titleAttr}">[[Image:{$filename}|{$thumbWidth}x{$thumbWidth}px]]</div>
</td>
END;
        }
        return $imageText;
    }
 /**
  * Returns image height.
  * @return int
  */
 public function getHeight()
 {
     return $this->file === NULL ? parent::getHeight() : $this->height;
 }
Example #25
0
 # Storing our image
 $img_details = $_JPOST->images[$i];
 # Getting our image
 $tmpimg = new Image();
 $tmpimg->load($img_details->src);
 # Our dimentions
 $x = (int) $img_details->x;
 $y = (int) $img_details->y;
 $width = (int) $img_details->width;
 $height = (int) $img_details->height;
 $rotate = (double) $img_details->rotate;
 switch ($img_details->size) {
     case 'contain':
         # Calaulating our actual widths/heights
         $px = $width / $tmpimg->getWidth();
         $py = $height / $tmpimg->getHeight();
         # Getting our percentages
         if ($px >= $py) {
             $py /= $px;
             $px = 1.0;
         } else {
             $px /= $py;
             $py = 1.0;
         }
         # Calculating our new positions
         $x += ($width - $width * $py) * 0.5;
         $y += ($height - $height * $px) * 0.5;
         $width = $width * $py;
         $height = $height * $px;
         break;
 }
Example #26
0
 public function uploadImage()
 {
     if (!$this->auth->isLogged()) {
         $this->security_log->write('Try to upload image from guest request');
         exit;
     }
     if (!$this->request->isAjax()) {
         $this->security_log->write('Try to upload image without ajax request');
         exit;
     }
     $json = array('error_message' => tt('Undefined upload error'));
     if ('POST' == $this->request->getRequestMethod() && $this->_validateImage()) {
         // Create user's folder if not exists
         if (!is_dir(DIR_STORAGE . $this->auth->getId())) {
             mkdir(DIR_STORAGE . $this->auth->getId(), 0755);
         }
         $image = new Image($this->request->files['image']['tmp_name'][$this->request->get['row']]);
         // Resize to default original format
         if (PRODUCT_IMAGE_ORIGINAL_WIDTH < $image->getWidth() || PRODUCT_IMAGE_ORIGINAL_HEIGHT < $image->getHeight()) {
             $image->resize(PRODUCT_IMAGE_ORIGINAL_WIDTH, PRODUCT_IMAGE_ORIGINAL_HEIGHT, 1, false, true);
         }
         $image_path = DIR_STORAGE . $this->auth->getId() . DIR_SEPARATOR;
         $image_filename = '_' . sha1(rand() . microtime() . $this->auth->getId());
         // Save image to the temporary file
         if ($image->save($image_path . $image_filename . '.' . STORAGE_IMAGE_EXTENSION)) {
             $json = array('success_message' => tt('Image successfully uploaded!'), 'url' => $this->cache->image($image_filename, $this->auth->getId(), 36, 36), 'product_image_id' => $image_filename);
         }
     } else {
         if (isset($this->_error['image']['common'])) {
             $json = array('error_message' => $this->_error['image']['common']);
         }
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }
Example #27
0
 public function tag(Image $img)
 {
     return "<img src = \"{$img->getPath()}\" alt=\"\" width=\"{$img->getWidth()}\" height=\"{$img->getHeight()}\" />";
 }
Example #28
0
 public function uploadAvatar()
 {
     if (!$this->auth->isLogged()) {
         $this->security_log->write('Try to upload image from guest request');
         exit;
     }
     if (!$this->request->isAjax()) {
         $this->security_log->write('Try to upload image without ajax request');
         exit;
     }
     $json = array('error_message' => tt('Undefined upload error'));
     if ('POST' == $this->request->getRequestMethod() && $this->_validateAvatar()) {
         // If image file looks good, lets prepare temporary save it
         $image = new Image($this->request->files['avatar']['tmp_name']);
         // Resize to default original format
         if (USER_IMAGE_ORIGINAL_WIDTH < $image->getWidth() || USER_IMAGE_ORIGINAL_HEIGHT < $image->getHeight()) {
             $image->resize(USER_IMAGE_ORIGINAL_WIDTH, USER_IMAGE_ORIGINAL_HEIGHT);
         }
         // Return result
         $filename = DIR_STORAGE . $this->auth->getId() . DIR_SEPARATOR . 'thumb' . '.' . ALLOWED_IMAGE_EXTENSION;
         if ($image->save($filename)) {
             $json = array('success_message' => tt('Image successfully uploaded!'), 'url' => $this->cache->image('thumb', $this->auth->getId(), 100, 100, false, true) . '?update=' . time());
         }
     } else {
         if (isset($this->_error['common'])) {
             $json = array('error_message' => $this->_error['common']);
         }
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }
Example #29
0
 /**
  * handle admin overview request
  */
 private function handleAdminOverview()
 {
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $page = $this->getPage();
     $this->pagerUrl->setParameter($view->getUrlId(), $view->getType());
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $url = new Url(true);
     $url->clearParameter('id');
     $url_new = clone $url;
     $url_new->setParameter($view->getUrlId(), ViewManager::ADMIN_NEW);
     $template->setVariable('href_new', $url_new->getUrl(true), false);
     $url_update = clone $url;
     $url_update->setParameter($view->getUrlId(), self::VIEW_UPDATE);
     $template->setVariable('href_update', $url_update->getUrl(true), false);
     $url_edit = clone $url;
     $url_edit->setParameter($view->getUrlId(), ViewManager::ADMIN_EDIT);
     $url_config = clone $url;
     $url_config->setParameter($view->getUrlId(), self::VIEW_CONFIG);
     $url_export = clone $url;
     $url_export->setParameter($view->getUrlId(), self::VIEW_EXPORT);
     $url_del = clone $url;
     $url_del->setParameter($view->getUrlId(), ViewManager::ADMIN_DELETE);
     $searchcriteria = array();
     $list = $this->getList(NULL, $this->pagesize, $page);
     foreach ($list['data'] as &$item) {
         $url_edit->setParameter('id', $item['id']);
         $url_config->setParameter('id', $item['id']);
         $url_export->setParameter('id', $item['id']);
         $url_del->setParameter('id', $item['id']);
         $item['href_edit'] = $url_edit->getUrl(true);
         $item['href_config'] = $url_config->getUrl(true);
         $item['href_export'] = $url_export->getUrl(true);
         $item['href_del'] = $url_del->getUrl(true);
         if ($item['image']) {
             try {
                 $img = new Image($item['image'], $this->getContentPath(true));
                 $item['image'] = array('src' => $this->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
             } catch (Exception $err) {
             }
         }
     }
     $template->setVariable('list', $list, false);
     $this->template[$this->director->theme->getConfig()->main_tag] = $template;
 }
Example #30
0
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$results = split("\n", trim(curl_exec($ch)));
foreach ($results as $line) {
    if (strtok($line, ':') == 'Content-Type') {
        $parts = explode(":", $line);
        if (substr(trim($parts[1]), 0, 6) != 'image/') {
            exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_IMAGE . $line);
        }
    }
}
# Getting our image
$img = new Image();
$img->load($_JPOST->src);
# Checking our image
if ((int) $img->getWidth() < 1 || (int) $img->getHeight() < 1) {
    exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_IMAGE);
}
# Making sure we have our open directories
$G_PATH_DATA = parse_path($_JPOST->dir, $_ENDPOINT, $G_TOKEN_SESSION_DATA);
$G_DIRECTORY_DATA = directory_hierarchy($G_STORAGE_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $G_PATH_DATA->absolute, $G_APP_DATA['img_auto_makedir'] == 1);
# If we aren't allowed we exit
check_directory_blacklisted($G_CONTROLLER_DBLINK, $G_TOKEN_DATA['id'], $G_TOKEN_SESSION_DATA, $G_DIRECTORY_DATA['path'] . $G_DIRECTORY_DATA['name']);
# Getting our server where we are going to store the images
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_SERVERS_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`server_type`\t='image' AND\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "'\n\t\t\tORDER BY\n\t\t\t\t`tier` ASC,\n\t\t\t\t`available_space` DESC\n\t\t\tLIMIT 1";
$G_SERVER_DATA = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
# Combining our host properties into our path
$G_SERVER_HOST = NQ_FILE_STORAGE_PROTOCOL . $G_SERVER_DATA['username'] . NQ_FILE_STORAGE_CRED_SEPARATOR . $G_SERVER_DATA['password'] . NQ_FILE_STORAGE_HOST_SEPARATOR . $G_SERVER_DATA['host'] . $G_SERVER_DATA['path'];
# Getting our metadata
$filename = $_JPOST->name;
$created = date('Y-m-d H:i:s');