getWidth() 공개 메소드

public getWidth ( )
예제 #1
0
파일: account.php 프로젝트: hutdast/rip
 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;
 }
예제 #2
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();
 }
예제 #3
0
		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();
		}
예제 #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;
     }
 }
예제 #5
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();
 }
예제 #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->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;
 }
예제 #7
0
파일: Post.php 프로젝트: Godefroy/iseplive
    /**
     * Add a post
     */
    public function iframe_add()
    {
        $this->setView('iframe_add.php');
        @set_time_limit(0);
        $uploaded_files = array();
        try {
            if (!isset(User_Model::$auth_data)) {
                throw new Exception(__('POST_ADD_ERROR_SESSION_EXPIRED'));
            }
            $is_student = isset(User_Model::$auth_data['student_number']);
            // Message
            $message = isset($_POST['message']) ? trim($_POST['message']) : '';
            if ($message == '' || $message == __('PUBLISH_DEFAULT_MESSAGE')) {
                throw new Exception(__('POST_ADD_ERROR_NO_MESSAGE'));
            }
            $message = preg_replace('#\\n{2,}#', "\n\n", $message);
            // Category
            if (!isset($_POST['category']) || !ctype_digit($_POST['category'])) {
                throw new Exception(__('POST_ADD_ERROR_NO_CATEGORY'));
            }
            $category = (int) $_POST['category'];
            // Official post (in a group)
            $official = isset($_POST['official']);
            // Group
            $group = isset($_POST['group']) && ctype_digit($_POST['group']) ? (int) $_POST['group'] : 0;
            if ($group == 0) {
                $group = null;
                $official = false;
            } else {
                $groups_auth = Group_Model::getAuth();
                if (isset($groups_auth[$group])) {
                    if ($official && !$groups_auth[$group]['admin']) {
                        throw new Exception(__('POST_ADD_ERROR_OFFICIAL'));
                    }
                } else {
                    throw new Exception(__('POST_ADD_ERROR_GROUP_NOT_FOUND'));
                }
            }
            // Private message
            $private = isset($_POST['private']);
            if ($private && !$is_student) {
                throw new Exception(__('POST_ADD_ERROR_PRIVATE'));
            }
            $attachments = array();
            // Photos
            if (isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $type = $img->getType();
                            if ($type == IMAGETYPE_JPEG) {
                                $ext = 'jpg';
                            } else {
                                if ($type == IMAGETYPE_GIF) {
                                    $ext = 'gif';
                                } else {
                                    if ($type == IMAGETYPE_PNG) {
                                        $ext = 'png';
                                    } else {
                                        throw new Exception();
                                    }
                                }
                            }
                            if ($img->getWidth() > 800) {
                                $img->setWidth(800, true);
                            }
                            $img->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
            }
            // Vidéos
            /* @uses PHPVideoToolkit : http://code.google.com/p/phpvideotoolkit/
             * @requires ffmpeg, php5-ffmpeg
             */
            if (isset($_FILES['attachment_video']) && is_array($_FILES['attachment_video']['name'])) {
                foreach ($_FILES['attachment_video']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_VIDEO) {
                        throw new Exception(__('POST_ADD_ERROR_VIDEO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_VIDEO))));
                    }
                }
                if ($filepaths = File::upload('attachment_video')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_video']['name'][$i]) ? $_FILES['attachment_video']['name'][$i] : '';
                        try {
                            $video = new ffmpeg_movie($filepath, false);
                            if (!$video->hasVideo()) {
                                throw new Exception('No video stream found in the file');
                            }
                            if (!$video->hasAudio()) {
                                throw new Exception('No audio stream found in the file');
                            }
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_VIDEO_FORMAT'));
                        }
                        // Video conversion
                        try {
                            $video_current_width = $video->getFrameWidth();
                            $video_width = min($video_current_width, Config::VIDEO_MAX_WIDTH);
                            if ($video_width % 2 == 1) {
                                // Even number required
                                $video_width--;
                            }
                            $video_height = $video_width * $video->getFrameHeight() / $video_current_width;
                            if ($video_height % 2 == 1) {
                                // Even number required
                                $video_height--;
                            }
                            // Extract thumb
                            $video_thumb = $video->getFrame(round($video->getFrameCount() * 0.2));
                            unset($video);
                            $video_thumb = $video_thumb->toGDImage();
                            $thumbpath = DATA_DIR . Config::DIR_DATA_TMP . File::getName($filepath) . '.thumb';
                            imagejpeg($video_thumb, $thumbpath, 95);
                            unset($video_thumb);
                            $img = new Image();
                            $img->load($thumbpath);
                            $img->setWidth($video_width, true);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            $uploaded_files[] = $thumbpath;
                            unset($img);
                            // Convert to FLV
                            if (!preg_match('#\\.flv$#i', $filepath)) {
                                $toolkit = new PHPVideoToolkit();
                                $toolkit->on_error_die = true;
                                // Will throw exception on error
                                $toolkit->setInputFile($filepath);
                                $toolkit->setVideoOutputDimensions($video_width, $video_height);
                                $toolkit->setFormatToFLV(Config::VIDEO_SAMPLING_RATE, Config::VIDEO_AUDIO_BIT_RATE);
                                $toolkit->setOutput(DATA_DIR . Config::DIR_DATA_TMP, File::getName($filepath) . '.flv', PHPVideoToolkit::OVERWRITE_EXISTING);
                                $toolkit->execute(false, false);
                                // Multipass: false, Log: false
                                File::delete($filepath);
                                $filepath = $toolkit->getLastOutput();
                                $filepath = $filepath[0];
                                unset($toolkit);
                            }
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $filepath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_VIDEO_CONVERT') . $e->getMessage());
                        }
                    }
                }
            }
            // Audios
            if (isset($_FILES['attachment_audio']) && is_array($_FILES['attachment_audio']['name'])) {
                foreach ($_FILES['attachment_audio']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_AUDIO) {
                        throw new Exception(__('POST_ADD_ERROR_AUDIO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_AUDIO))));
                    }
                }
                if ($filepaths = File::upload('attachment_audio')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        if (!preg_match('#\\.mp3$#', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_AUDIO_FORMAT'));
                        }
                        $name = isset($_FILES['attachment_audio']['name'][$i]) ? $_FILES['attachment_audio']['name'][$i] : '';
                        $attachments[] = array($filepath, $name);
                    }
                }
            }
            // Files
            if (isset($_FILES['attachment_file']) && is_array($_FILES['attachment_file']['name'])) {
                foreach ($_FILES['attachment_file']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_FILE) {
                        throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE))));
                    }
                }
                if ($filepaths = File::upload('attachment_file')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        if (!preg_match('#\\.[a-z0-9]{2,4}$#i', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
                        }
                        if (preg_match('#\\.(jpg|png|gif|mp3|flv)$#i', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT2'));
                        }
                        $name = isset($_FILES['attachment_file']['name'][$i]) ? $_FILES['attachment_file']['name'][$i] : '';
                        $attachments[] = array($filepath, $name);
                    }
                }
            }
            // Event
            if (isset($_POST['event_title']) && isset($_POST['event_start']) && isset($_POST['event_end'])) {
                // Title
                $event_title = trim($_POST['event_title']);
                if ($event_title == '') {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_NO_TITLE'));
                }
                // Dates
                if (!($event_start = strptime($_POST['event_start'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE'));
                }
                if (!($event_end = strptime($_POST['event_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE'));
                }
                $event_start = mktime($event_start['tm_hour'], $event_start['tm_min'], 0, $event_start['tm_mon'] + 1, $event_start['tm_mday'], $event_start['tm_year'] + 1900);
                $event_end = mktime($event_end['tm_hour'], $event_end['tm_min'], 0, $event_end['tm_mon'] + 1, $event_end['tm_mday'], $event_end['tm_year'] + 1900);
                if ($event_start > $event_end) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE_ORDER'));
                }
                $event = array($event_title, $event_start, $event_end);
            } else {
                $event = null;
            }
            // Survey
            if (isset($_POST['survey_question']) && isset($_POST['survey_end']) && isset($_POST['survey_answer']) && is_array($_POST['survey_answer'])) {
                // Question
                $survey_question = trim($_POST['survey_question']);
                if ($survey_question == '') {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_NO_QUESTION'));
                }
                // Date
                if (!($survey_end = strptime($_POST['survey_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_DATE'));
                }
                $survey_end = mktime($survey_end['tm_hour'], $survey_end['tm_min'], 0, $survey_end['tm_mon'] + 1, $survey_end['tm_mday'], $survey_end['tm_year'] + 1900);
                // Multiple answers
                $survey_multiple = isset($_POST['survey_multiple']);
                // Answers
                $survey_answers = array();
                foreach ($_POST['survey_answer'] as $survey_answer) {
                    $survey_answer = trim($survey_answer);
                    if ($survey_answer != '') {
                        $survey_answers[] = $survey_answer;
                    }
                }
                if (count($survey_answers) < 2) {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_ANSWERS'));
                }
                $survey = array($survey_question, $survey_end, $survey_multiple, $survey_answers);
            } else {
                $survey = null;
            }
            // Creation of the post
            $id = $this->model->addPost((int) User_Model::$auth_data['id'], $message, $category, $group, $official, $private);
            // Attach files
            foreach ($attachments as $attachment) {
                $this->model->attachFile($id, $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null);
            }
            // Event
            if (isset($event)) {
                $this->model->attachEvent($id, $event[0], $event[1], $event[2]);
            }
            // Survey
            if (isset($survey)) {
                $this->model->attachSurvey($id, $survey[0], $survey[1], $survey[2], $survey[3]);
            }
            $this->addJSCode('
				parent.location = "' . Config::URL_ROOT . Routes::getPage('home') . '";
			');
        } catch (Exception $e) {
            // Delete all uploading files in tmp
            foreach ($uploaded_files as $uploaded_file) {
                File::delete($uploaded_file);
            }
            $this->addJSCode('
				with(parent){
					Post.errorForm(' . json_encode($e->getMessage()) . ');
				}
			');
        }
    }
예제 #8
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);
 }
예제 #9
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);
 }
예제 #10
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;
 }
예제 #11
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;
     }
 }
예제 #12
0
for ($i = 0, $icount = count($_JPOST->images); $i < $icount; $i++) {
    # 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;
예제 #13
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;
 }
예제 #14
0
파일: proxy.php 프로젝트: adollar/patterns
 public function tag(Image $img)
 {
     return "<img src = \"{$img->getPath()}\" alt=\"\" width=\"{$img->getWidth()}\" height=\"{$img->getHeight()}\" />";
 }
예제 #15
0
파일: Group.php 프로젝트: Godefroy/iseplive
 /**
  * Add a group
  */
 public function add($params)
 {
     $this->setView('add.php');
     $this->setTitle(__('GROUP_ADD_TITLE'));
     $is_logged = isset(User_Model::$auth_data);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // Authorization
     if (!$is_admin) {
         throw new ActionException('Page', 'error404');
     }
     $group = array();
     // Saving data
     if (isset($_POST['name']) && isset($_POST['creation_date']) && isset($_POST['mail']) && isset($_POST['description'])) {
         $uploaded_files = array();
         try {
             // Members
             $members = array();
             if (isset($_POST['members_ids']) && is_array($_POST['members_ids'])) {
                 foreach ($_POST['members_ids'] as $id) {
                     if (ctype_digit($id)) {
                         $id = (int) $id;
                         $members[$id] = array('title' => isset($_POST['member_title_' . $id]) ? $_POST['member_title_' . $id] : '', 'admin' => isset($_POST['member_admin_' . $id]));
                     }
                 }
             }
             // Other info
             $data = array('name' => $_POST['name'], 'creation_date' => $_POST['creation_date'], 'mail' => $_POST['mail'], 'description' => $_POST['description'], 'members' => $members);
             // Avatar
             if (isset($_FILES['avatar']) && !is_array($_FILES['avatar']['name'])) {
                 if ($_FILES['avatar']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                     throw new FormException('avatar');
                 }
                 if ($avatarpath = File::upload('avatar')) {
                     $uploaded_files[] = $avatarpath;
                     try {
                         $img = new Image();
                         $img->load($avatarpath);
                         $type = $img->getType();
                         if ($type == IMAGETYPE_JPEG) {
                             $ext = 'jpg';
                         } else {
                             if ($type == IMAGETYPE_GIF) {
                                 $ext = 'gif';
                             } else {
                                 if ($type == IMAGETYPE_PNG) {
                                     $ext = 'png';
                                 } else {
                                     throw new Exception();
                                 }
                             }
                         }
                         if ($img->getWidth() > 800) {
                             $img->setWidth(800, true);
                         }
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarpath);
                         // Thumb
                         $avatarthumbpath = $avatarpath . '.thumb';
                         $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarthumbpath);
                         unset($img);
                         $uploaded_files[] = $avatarthumbpath;
                         $data['avatar_path'] = $avatarthumbpath;
                         $data['avatar_big_path'] = $avatarpath;
                     } catch (Exception $e) {
                         throw new FormException('avatar');
                     }
                 }
             }
             $url_name = $this->model->create($data);
             Routes::redirect('group', array('group' => $url_name));
         } catch (FormException $e) {
             foreach ($uploaded_files as $uploaded_file) {
                 File::delete($uploaded_file);
             }
             foreach ($data as $key => $value) {
                 $group[$key] = $value;
             }
             $group['members'] = Student_Model::getInfoByUsersIds(array_keys($members));
             foreach ($group['members'] as &$member) {
                 if (isset($members[(int) $member['user_id']])) {
                     $member['title'] = $members[(int) $member['user_id']]['title'];
                     $member['admin'] = $members[(int) $member['user_id']]['admin'] ? '1' : '0';
                 }
             }
             $this->set('form_error', $e->getError());
         }
     }
     $this->set('group', $group);
     $this->addJSCode('Group.initEdit();');
 }
예제 #16
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));
 }
예제 #17
0
 /**
  * @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);
 }
예제 #18
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;
 }
예제 #19
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);
 }
예제 #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(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;
 }
예제 #21
0
파일: Family.php 프로젝트: k-hasan-19/wiki
    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;
    }
예제 #22
0
파일: main.php 프로젝트: 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);
        }
    }
예제 #23
0
파일: filemanager.php 프로젝트: hutdast/rip
 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));
 }
예제 #24
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));
 }
예제 #25
0
파일: Image.php 프로젝트: kofel/gutenberg
 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;
 }
예제 #26
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');
예제 #27
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;
 }
예제 #28
0
 /**
  * Returns image width.
  * @return int
  */
 public function getWidth()
 {
     return $this->file === NULL ? parent::getWidth() : $this->width;
 }
예제 #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;
 }
예제 #30
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));
 }