• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP JImage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中JImage的典型用法代码示例。如果您正苦于以下问题:PHP JImage类的具体用法?PHP JImage怎么用?PHP JImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了JImage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: setup

 /**
  * Method to attach a JForm object to the field.
  *  Catch upload files when form setup.
  *
  * @param   object  &$element  The JXmlElement object representing the <field /> tag for the form field object.
  * @param   mixed   $value     The form field value to validate.
  * @param   string  $group     The field name group control value. This acts as as an array container for the field.
  *                              For example if the field has name="foo" and the group value is set to "bar" then the
  *                              full field name would end up being "bar[foo]".
  *
  * @return  boolean  True on success.
  */
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     parent::setup($element, $value, $group);
     if (JRequest::getVar($this->element['name'] . '_delete') == 1) {
         $this->value = '';
     } else {
         // Upload Image
         // ===============================================
         if (isset($_FILES['jform']['name']['profile'])) {
             foreach ($_FILES['jform']['name']['profile'] as $key => $var) {
                 if (!$var) {
                     continue;
                 }
                 // Get Field Attr
                 $width = $this->element['save_width'] ? $this->element['save_width'] : 800;
                 $height = $this->element['save_height'] ? $this->element['save_height'] : 800;
                 // Build File name
                 $src = $_FILES['jform']['tmp_name']['profile'][$key];
                 $var = explode('.', $var);
                 $date = JFactory::getDate('now', JFactory::getConfig()->get('offset'));
                 $name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var);
                 $url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name;
                 // A Event for extend.
                 JFactory::getApplication()->triggerEvent('onCCKEngineUploadImage', array(&$url, &$this, &$this->element));
                 $dest = JPATH_ROOT . '/' . $url;
                 // Upload First
                 JFile::upload($src, $dest);
                 // Resize image
                 $img = new JImage();
                 $img->loadFile(JPATH_ROOT . '/' . $url);
                 $img = $img->resize($width, $height);
                 switch (array_pop($var)) {
                     case 'gif':
                         $type = IMAGETYPE_GIF;
                         break;
                     case 'png':
                         $type = IMAGETYPE_PNG;
                         break;
                     default:
                         $type = IMAGETYPE_JPEG;
                         break;
                 }
                 // save
                 $img->toFile($dest, $type, array('quality' => 85));
                 // Set in Value
                 $this->value = $url;
             }
         }
     }
     return true;
 }
开发者ID:ForAEdesWeb,项目名称:AEW3,代码行数:63,代码来源:uploadimage.php


示例2: renderFeature

 public function renderFeature()
 {
     //Retina Image
     if ($this->helix3->getParam('logo_type') == 'image') {
         jimport('joomla.image.image');
         if ($this->helix3->getParam('logo_image')) {
             $path = JPATH_ROOT . '/' . $this->helix3->getParam('logo_image');
         } else {
             $path = JPATH_ROOT . '/templates/' . $this->helix3->getTemplate() . '/images/presets/' . $this->helix3->Preset() . '/logo.png';
         }
         if (file_exists($path)) {
             $image = new JImage($path);
             $width = $image->getWidth();
             $height = $image->getHeight();
         } else {
             $width = '';
             $height = '';
         }
     }
     $html = '';
     $custom_logo_class = '';
     $sitename = JFactory::getApplication()->get('sitename');
     if ($this->helix3->getParam('mobile_logo')) {
         $custom_logo_class = ' hidden-xs';
     }
     $html .= '<a class="logo" href="' . JURI::base(true) . '/">';
     if ($this->helix3->getParam('logo_type') == 'image') {
         if ($this->helix3->getParam('logo_image')) {
             $html .= '<div>';
             $html .= '<img class="sp-default-logo' . $custom_logo_class . '" src="' . $this->helix3->getParam('logo_image') . '" alt="' . $sitename . '">';
             if ($this->helix3->getParam('logo_image_2x')) {
                 $html .= '<img class="sp-retina-logo' . $custom_logo_class . '" src="' . $this->helix3->getParam('logo_image_2x') . '" alt="' . $sitename . '" width="' . $width . '" height="' . $height . '">';
             }
             if ($this->helix3->getParam('mobile_logo')) {
                 $html .= '<img class="sp-default-logo visible-xs" src="' . $this->helix3->getParam('mobile_logo') . '" alt="' . $sitename . '">';
             }
             $html .= '</div>';
         } else {
             $html .= '<div>';
             $html .= '<img class="sp-default-logo' . $custom_logo_class . '" src="' . $this->helix3->getTemplateUri() . '/images/presets/' . $this->helix3->Preset() . '/logo.png" alt="' . $sitename . '">';
             $html .= '<img class="sp-retina-logo' . $custom_logo_class . '" src="' . $this->helix3->getTemplateUri() . '/images/presets/' . $this->helix3->Preset() . '/[email protected]" alt="' . $sitename . '" width="' . $width . '" height="' . $height . '">';
             if ($this->helix3->getParam('mobile_logo')) {
                 $html .= '<img class="sp-default-logo visible-xs" src="' . $this->helix3->getParam('mobile_logo') . '" alt="' . $sitename . '">';
             }
             $html .= '</div>';
         }
     } else {
         if ($this->helix3->getParam('logo_text')) {
             $html .= '<div>' . $this->helix3->divtParam('logo_text') . '</div>';
         } else {
             $html .= '<div>' . $sitename . '</div>';
         }
         if ($this->helix3->getParam('logo_slogan')) {
             $html .= '<p class="logo-slogan">' . $this->helix3->getParam('logo_slogan') . '</p>';
         }
     }
     $html .= '<div class="site-name">' . $sitename . '</div>';
     $html .= '</a>';
     return $html;
 }
开发者ID:spiridonov-oa,项目名称:remontvolt,代码行数:60,代码来源:logo.php


示例3: createThumb

 public static function createThumb($path, $width = 100, $height = 100, $crop = 2)
 {
     $myImage = new JImage();
     $myImage->loadFile(JPATH_SITE . DS . $path);
     if ($myImage->isLoaded()) {
         // $filename = end(explode('/', $path));
         $filename = JFile::getName($path);
         $filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
         $newfilename = $width . 'x' . $height . '_' . $filefolder . '_' . JFile::makeSafe($filename);
         $fileExists = JFile::exists(JPATH_CACHE . '/' . $newfilename);
         if (!$fileExists) {
             $resizedImage = $myImage->resize($width, $height, true, $crop);
             $properties = $myImage->getImageFileProperties($path);
             $mime = $properties->mime;
             if ($mime == 'image/jpeg') {
                 $type = IMAGETYPE_JPEG;
             } elseif ($mime = 'image/png') {
                 $type = IMAGETYPE_PNG;
             } elseif ($mime = 'image/gif') {
                 $type = IMAGETYPE_GIF;
             }
             $resizedImage->toFile(JPATH_CACHE . '/' . $newfilename, $type);
         }
         return $newfilename;
     } else {
         return "My file is not loaded";
     }
 }
开发者ID:quyip8818,项目名称:joomla,代码行数:28,代码来源:helper.php


示例4: resetThumbs

 public function resetThumbs()
 {
     $items = self::getItems();
     //Get Params
     $params = JComponentHelper::getParams('com_spsimpleportfolio');
     $square = strtolower($params->get('square', '600x600'));
     $rectangle = strtolower($params->get('rectangle', '600x400'));
     $tower = strtolower($params->get('tower', '600x800'));
     $cropratio = $params->get('cropratio', 4);
     if (count($items)) {
         //Removing old thumbs
         foreach ($items as $item) {
             $folder = JPATH_ROOT . '/images/spsimpleportfolio/' . $item->alias;
             if (JFolder::exists($folder)) {
                 JFolder::delete($folder);
             }
         }
         //Creating Thumbs
         foreach ($items as $item) {
             $image = JPATH_ROOT . '/' . $item->image;
             $path = JPATH_ROOT . '/images/spsimpleportfolio/' . $item->alias;
             if (!file_exists($path)) {
                 JFolder::create($path, 0755);
             }
             $sizes = array($square, $rectangle, $tower);
             $image = new JImage($image);
             $image->createThumbs($sizes, $cropratio, $path);
         }
     }
     $this->setRedirect('index.php?option=com_config&view=component&component=com_spsimpleportfolio&path=&return=' . base64_encode('index.php?option=com_spsimpleportfolio'), 'Thumbnails generated.');
 }
开发者ID:katebmedia,项目名称:SP-Simple-Portfolio,代码行数:31,代码来源:thumbs.php


示例5: createThumbnail

 /**
  * Create a thumbnail from an image file.
  *
  * <code>
  * $myFile   = "/tmp/myfile.jpg";
  *
  * $options = array(
  *     "destination" => "image/mypic.jpg",
  *     "width" => 200,
  *     "height" => 200,
  *     "scale" => JImage::SCALE_INSIDE
  * );
  *
  * $file = new PrismFileImage($myFile);
  * $file->createThumbnail($options);
  *
  * </code>
  *
  * @param  array $options Some options used in the process of generating thumbnail.
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  *
  * @return string A location to the new file.
  */
 public function createThumbnail($options)
 {
     $width = ArrayHelper::getValue($options, "width", 100);
     $height = ArrayHelper::getValue($options, "height", 100);
     $scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
     $destination = ArrayHelper::getValue($options, "destination");
     if (!$destination) {
         throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
     }
     // Generate thumbnail.
     $image = new \JImage();
     $image->loadFile($this->file);
     if (!$image->isLoaded()) {
         throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
     }
     // Resize the file as a new object
     $thumb = $image->resize($width, $height, true, $scale);
     $fileName = basename($this->file);
     $ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
     switch ($ext) {
         case "gif":
             $type = IMAGETYPE_GIF;
             break;
         case "png":
             $type = IMAGETYPE_PNG;
             break;
         case IMAGETYPE_JPEG:
         default:
             $type = IMAGETYPE_JPEG;
     }
     $thumb->toFile($destination, $type);
     return $destination;
 }
开发者ID:pashakiz,项目名称:crowdf,代码行数:58,代码来源:Image.php


示例6: resize

 /**
  * Resize an image, auto catch it from remote host and generate a new thumb in cache dir.
  *
  * @param   string  $url       Image URL, recommend a absolute URL.
  * @param   integer $width     Image width, do not include 'px'.
  * @param   integer $height    Image height, do not include 'px'.
  * @param   int     $method    Crop or not.
  * @param   integer $q         Image quality
  * @param   string  $file_type File type.
  *
  * @return  string  The cached thumb URL.
  */
 public function resize($url = null, $width = 100, $height = 100, $method = \JImage::SCALE_INSIDE, $q = 85, $file_type = 'jpg')
 {
     if (!$url) {
         return $this->getDefaultImage($width, $height, $method, $q, $file_type);
     }
     $path = $this->getImagePath($url);
     try {
         $img = new \JImage();
         if (\JFile::exists($path)) {
             $img->loadFile($path);
         } else {
             return $this->getDefaultImage($width, $height, $method, $q, $file_type);
         }
         // If file type not png or gif, use jpg as default.
         if ($file_type != 'png' && $file_type != 'gif') {
             $file_type = 'jpg';
         }
         // Using md5 hash
         $handler = $this->hashHandler;
         $file_name = $handler($url . $width . $height . $method . $q) . '.' . $file_type;
         $file_path = $this->config['path.cache'] . '/' . $file_name;
         $file_url = trim($this->config['url.cache'], '/') . '/' . $file_name;
         // Img exists?
         if (\JFile::exists($file_path)) {
             return $file_url;
         }
         // Crop
         if ($method === true) {
             $method = \JImage::CROP_RESIZE;
         } elseif ($method === false) {
             $method = \JImage::SCALE_INSIDE;
         }
         $img = $img->generateThumbs($width . 'x' . $height, $method);
         // Save
         switch ($file_type) {
             case 'gif':
                 $type = IMAGETYPE_GIF;
                 break;
             case 'png':
                 $type = IMAGETYPE_PNG;
                 break;
             default:
                 $type = IMAGETYPE_JPEG;
                 break;
         }
         // Create folder
         if (!is_dir(dirname($file_path))) {
             \JFolder::create(dirname($file_path));
         }
         $img[0]->toFile($file_path, $type, array('quality' => $q));
         return $file_url;
     } catch (\Exception $e) {
         if (JDEBUG) {
             echo $e->getMessage();
         }
         return $this->getDefaultImage($width, $height, $method, $q, $file_type);
     }
 }
开发者ID:beingsane,项目名称:quickcontent,代码行数:70,代码来源:Thumb.php


示例7: check

 public function check()
 {
     $result = true;
     //Alias
     if (empty($this->alias)) {
         // Auto-fetch a alias
         $this->alias = JFilterOutput::stringURLSafe($this->title);
     } else {
         // Make sure nobody adds crap characters to the alias
         $this->alias = JFilterOutput::stringURLSafe($this->alias);
     }
     $existingAlias = FOFModel::getTmpInstance('Items', 'SpsimpleportfolioModel')->alias($this->alias)->getList(true);
     if (!empty($existingAlias)) {
         $count = 0;
         $k = $this->getKeyName();
         foreach ($existingAlias as $item) {
             if ($item->{$k} != $this->{$k}) {
                 $count++;
             }
         }
         if ($count) {
             $this->setError(JText::_('COM_SPSIMPLEPORTFOLIO_ALIAS_ERR_SLUGUNIQUE'));
             $result = false;
         }
     }
     //Tags
     if (is_array($this->spsimpleportfolio_tag_id)) {
         if (!empty($this->spsimpleportfolio_tag_id)) {
             $this->spsimpleportfolio_tag_id = json_encode($this->spsimpleportfolio_tag_id);
         }
     }
     if (is_null($this->spsimpleportfolio_tag_id) || empty($this->spsimpleportfolio_tag_id)) {
         $this->spsimpleportfolio_tag_id = '';
     }
     //Generate Thumbnails
     if ($result) {
         $params = JComponentHelper::getParams('com_spsimpleportfolio');
         $square = strtolower($params->get('square', '600x600'));
         $rectangle = strtolower($params->get('rectangle', '600x400'));
         $tower = strtolower($params->get('tower', '600x800'));
         $cropratio = $params->get('cropratio', 4);
         if (!is_null($this->image)) {
             jimport('joomla.filesystem.file');
             jimport('joomla.filesystem.folder');
             jimport('joomla.image.image');
             $image = JPATH_ROOT . '/' . $this->image;
             $path = JPATH_ROOT . '/images/spsimpleportfolio/' . $this->alias;
             if (!file_exists($path)) {
                 JFolder::create($path, 0755);
             }
             $sizes = array($square, $rectangle, $tower);
             $image = new JImage($image);
             $image->createThumbs($sizes, $cropratio, $path);
         }
     }
     return $result;
 }
开发者ID:katebmedia,项目名称:SP-Simple-Portfolio,代码行数:57,代码来源:item.php


示例8: getProportion

 public static function getProportion($path)
 {
     $myImage = new JImage();
     $imgPath = JPATH_SITE . DS . $path;
     $myImage->loadFile($imgPath);
     if ($myImage->isLoaded()) {
         $properties = $myImage->getImageFileProperties($imgPath);
         return $properties->height / $properties->width * 100;
     } else {
         return;
     }
 }
开发者ID:quyip8818,项目名称:joomla,代码行数:12,代码来源:helper.php


示例9: create

 public function create()
 {
     $output = '';
     $size = JRequest::getCmd('size', '');
     if (!in_array($size, array('min', 'medium'))) {
         throw new Exception('The image size is not recognized', 500);
     }
     $image = JRequest::getVar('image', '');
     $id = JRequest::getInt('id', 0);
     $imagePath = JPATH_ROOT . DS . 'images' . DS . 'com_jea' . DS . 'images' . DS . $id . DS . $image;
     $thumbDir = JPATH_ROOT . DS . 'images' . DS . 'com_jea' . DS . 'thumb-' . $size;
     $thumbPath = $thumbDir . DS . $id . '-' . $image;
     if (file_exists($thumbPath)) {
         $output = readfile($thumbPath);
     } elseif (file_exists($imagePath)) {
         if (!JFolder::exists($thumbPath)) {
             JFolder::create($thumbDir);
         }
         $params = JComponentHelper::getParams('com_jea');
         if ($size == 'medium') {
             $width = $params->get('thumb_medium_width', 400);
             $height = $params->get('thumb_medium_height', 300);
         } else {
             $width = $params->get('thumb_min_width', 120);
             $height = $params->get('thumb_min_height', 90);
         }
         $quality = (int) $params->get('jpg_quality', 90);
         $cropThumbnails = (bool) $params->get('crop_thumbnails', 0);
         $JImage = new JImage($imagePath);
         if ($cropThumbnails) {
             $thumb = $JImage->resize($width, $height, true, JImage::SCALE_OUTSIDE);
             $left = $thumb->getWidth() > $width ? intval(($thumb->getWidth() - $width) / 2) : 0;
             $top = $thumb->getHeight() > $height ? intval(($thumb->getHeight() - $height) / 2) : 0;
             $thumb->crop($width, $height, $left, $top, false);
         } else {
             $thumb = $JImage->resize($width, $height);
         }
         $thumb->toFile($thumbPath, IMAGETYPE_JPEG, array('quality' => $quality));
         $output = readfile($thumbPath);
     } else {
         throw new Exception('The image ' . $image . ' was not found', 500);
     }
     JResponse::setHeader('Content-Type', 'image/jpeg', true);
     JResponse::setHeader('Content-Transfer-Encoding', 'binary');
     JResponse::allowCache(false);
     JResponse::setBody($output);
     echo JResponse::toString();
     exit;
 }
开发者ID:Cloudum,项目名称:com_jea,代码行数:49,代码来源:thumbnail.php


示例10: onMediaEditorProcess

 public function onMediaEditorProcess($filePath)
 {
     jimport('joomla.filesystem.file');
     $image = new JImage($filePath);
     if ($image->isLoaded() == false) {
         throw new LogicException('Failed to load image');
     }
     $image->rotate(180, 0, false);
     $extension = JFile::getExt($filePath);
     if (in_array($extension, array('png', 'gif'))) {
         $imageType = $extension;
     } else {
         $imageType = 'jpg';
     }
     $image->toFile($filePath, $imageType);
 }
开发者ID:yireo,项目名称:plg_media-editor_example,代码行数:16,代码来源:example.php


示例11: getImages

 /**
  * Method to load the images from the relative source
  * 
  * @param  JRegistry $params The module params object
  * 
  * @return object[]          An array of image objects
  *
  * @since  1.0
  */
 public static function getImages($params)
 {
     // Create the folder path
     $folder = JPath::clean(JPATH_BASE . DIRECTORY_SEPARATOR . $params->get('image_folder'));
     $cacheFolder = JPath::clean(JPATH_BASE . '/cache/mod_qluegallery/thumbs/' . $params->get('image_folder'));
     // Make sure the folder we are trying to load actually exists
     if (!JFolder::exists($folder)) {
         JError::raiseWarning(500, JText::_('MOD_QLUEGALLERY_NO_FOLDER_EXISTS'));
         return null;
     }
     // Load all images from the folder
     $images = JFolder::files($folder, '\\.(?:gif|jpg|png|jpeg)$');
     // Limit our found images
     $images = array_slice($images, 0, (int) $params->get('limit', 1));
     // Loop through each image and apply the image path
     foreach ($images as $key => $image) {
         // Path to the file
         $file = JPath::clean($folder . '/' . $image);
         $dimensions = $params->get('thumbnail_width', 150) . 'x' . $params->get('thumbnail_height', 150);
         $thumbnail = pathinfo($image, PATHINFO_FILENAME);
         $thumbExt = pathinfo($image, PATHINFO_EXTENSION);
         $thumbnail .= '_' . $dimensions . '.' . $thumbExt;
         // Create our image object
         $img = new stdClass();
         $img->file = $image;
         $img->full_path = JUri::root(true) . str_replace(JPATH_BASE, '', $file);
         $img->properties = JImage::getImageFileProperties($file);
         $img->thumbnail = str_replace(JPATH_BASE, '', $cacheFolder . '/' . $thumbnail);
         // If the thumbnail does not exist, create it
         if (!file_exists($cacheFolder . DIRECTORY_SEPARATOR . $thumbnail)) {
             // Get the image source
             $gd = new JImage($file);
             // Create the thumb folder if it does not exist
             if (!JFolder::exists($cacheFolder)) {
                 JFolder::create($cacheFolder);
             }
             // Create the thumbnails
             $gd->createThumbs($dimensions, JImage::CROP_RESIZE, $cacheFolder);
         }
         // Make sure the file paths are safe to use
         $img->full_path = str_replace('\\', '/', $img->full_path);
         $img->thumbnail = str_replace('\\', '/', $img->thumbnail);
         $images[$key] = $img;
     }
     return $images;
 }
开发者ID:Ettore495,项目名称:Ettore-Work,代码行数:55,代码来源:folder.php


示例12: getFilterInstance

 /**
  * Allows public access to protected method.
  *
  * @param   string  $type  The image filter type to get.
  *
  * @return  JImageFilter
  *
  * @since   11.3
  * @throws  RuntimeException
  */
 public function getFilterInstance($type)
 {
     if ($this->mockFilter) {
         return $this->mockFilter;
     } else {
         return parent::getFilterInstance($type);
     }
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:18,代码来源:JImageInspector.php


示例13: resize

 public function resize($type, $width, $height, $crop = false)
 {
     if ($type == 'thumbnail') {
         $path = $this->gallery->getThumbnailsPath();
         $filePath =& $this->thumbnailFilepath;
         $scale = 3;
         // SCALE_OUTSIDE
         $options = array('quality' => 75);
         // TODO as param
     } else {
         if ($type == 'resized') {
             $path = $this->gallery->getResizedPath();
             $filePath =& $this->resizedFilepath;
             $scale = 2;
             // SCALE_INSIDE
             $options = array('quality' => 85);
             // TODO as param
         } else {
             return;
         }
     }
     // define file paths
     $newPhotoFilepath = $path . DS . $this->folder->getFolderPath() . DS . $this->filename;
     $photoFilepath = $this->gallery->getPhotosPath() . DS . $this->folder->getFolderPath() . DS . $this->filename;
     // check if thumbnail already exists and create it if not
     if (!JFile::exists($newPhotoFilepath)) {
         // TODO add check if file size (width and height) is correct
         // resize image
         $photo = new JImage($photoFilepath);
         $newPhoto = $photo->resize($width, $height, true, $scale);
         // crop image
         if ($crop) {
             $offsetLeft = ($newPhoto->getWidth() - $width) / 2;
             $offsetTop = ($newPhoto->getHeight() - $height) / 2;
             $newPhoto->crop($width, $height, $offsetLeft, $offsetTop, false);
         }
         // create folders (recursive) and write file
         if (JFolder::create($path . DS . $this->folder->getFolderPath())) {
             $newPhoto->toFile($newPhotoFilepath, IMAGETYPE_JPEG, $options);
         }
     }
     $filePath = str_replace($this->gallery->getCachePath(), '', $newPhotoFilepath);
 }
开发者ID:beingsane,项目名称:joomla-gallery,代码行数:43,代码来源:photo.php


示例14: resize

 /**
  * Resize an image, auto catch it from remote host and generate a new thumb in cache dir.
  *
  * @param   string  $url       Image URL, recommend a absolute URL.
  * @param   integer $width     Image width, do not include 'px'.
  * @param   integer $height    Image height, do not include 'px'.
  * @param   boolean $zc        Crop or not.
  * @param   integer $q         Image quality
  * @param   string  $file_type File type.
  *
  * @return  string  The cached thumb URL.
  */
 public static function resize($url = null, $width = 100, $height = 100, $zc = 0, $q = 85, $file_type = 'jpg')
 {
     if (!$url) {
         return self::getDefaultImage($width, $height, $zc, $q, $file_type);
     }
     $path = self::getImagePath($url);
     try {
         $img = new JImage();
         if (JFile::exists($path)) {
             $img->loadFile($path);
         } else {
             return self::getDefaultImage($width, $height, $zc, $q, $file_type);
         }
         // get Width Height
         $imgdata = JImage::getImageFileProperties($path);
         // set save data
         if ($file_type != 'png' && $file_type != 'gif') {
             $file_type = 'jpg';
         }
         $file_name = md5($url . $width . $height . $zc . $q . implode('', (array) $imgdata)) . '.' . $file_type;
         $file_path = self::$cache_path . DS . $file_name;
         $file_url = trim(self::$cache_url, '/') . '/' . $file_name;
         // img exists?
         if (JFile::exists($file_path)) {
             return $file_url;
         }
         // crop
         if ($zc) {
             $img = self::crop($img, $width, $height, $imgdata);
         }
         // resize
         $img = $img->resize($width, $height);
         // save
         switch ($file_type) {
             case 'gif':
                 $type = IMAGETYPE_GIF;
                 break;
             case 'png':
                 $type = IMAGETYPE_PNG;
                 break;
             default:
                 $type = IMAGETYPE_JPEG;
                 break;
         }
         JFolder::create(self::$cache_path);
         $img->toFile($file_path, $type, array('quality' => $q));
         return $file_url;
     } catch (Exception $e) {
         if (JDEBUG) {
             echo $e->getMessage();
         }
         return self::getDefaultImage($width, $height, $zc, $q, $file_type);
     }
 }
开发者ID:beingsane,项目名称:quickcontent,代码行数:66,代码来源:thumb.php


示例15: createThumb

 public static function createThumb($path, $width = 100, $height = 100, $crop = 2, $cachefolder = 'hgimages', $external = 0)
 {
     $myImage = new JImage();
     if (!$external) {
         $myImage->loadFile(JPATH_SITE . DS . $path);
     } else {
         $myImage->loadFile($path);
     }
     if ($myImage->isLoaded()) {
         // $filename = end(explode('/', $path));
         $filename = JFile::getName($path);
         $filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
         $newfilename = $width . 'x' . $height . 'x' . $crop . '_' . $filefolder . '_' . JFile::makeSafe($filename);
         $hgimages = JPATH_CACHE . '/' . $cachefolder . '/';
         if (!JFolder::exists($hgimages)) {
             JFolder::create($hgimages);
         }
         $fileExists = JFile::exists($hgimages . $newfilename);
         if (!$fileExists) {
             switch ($crop) {
                 // Case for self::CROP
                 case 4:
                     $resizedImage = $myImage->crop($width, $height, null, null, true);
                     break;
                     // Case for self::CROP_RESIZE
                 // Case for self::CROP_RESIZE
                 case 5:
                     $resizedImage = $myImage->cropResize($width, $height, true);
                     break;
                 default:
                     $resizedImage = $myImage->resize($width, $height, true, $crop);
                     break;
             }
             $properties = $myImage->getImageFileProperties($path);
             $mime = $properties->mime;
             if ($mime == 'image/jpeg') {
                 $type = IMAGETYPE_JPEG;
             } elseif ($mime = 'image/png') {
                 $type = IMAGETYPE_PNG;
             } elseif ($mime = 'image/gif') {
                 $type = IMAGETYPE_GIF;
             }
             $resizedImage->toFile($hgimages . $newfilename, $type);
         }
         return $newfilename;
     } else {
         return "My file is not loaded";
     }
 }
开发者ID:quyip8818,项目名称:joomla,代码行数:49,代码来源:shortcodes_helper.php


示例16: onContentAfterSave

 /**
  * Plugin that manipulate uploaded images
  *
  * @param   string   $context       The context of the content being passed to the plugin.
  * @param   object   &$object_file  The file object.
  *
  * @return  object  The file object.
  */
 public function onContentAfterSave($context, &$object_file)
 {
     // Are we in the right context?
     if ($context != 'com_media.file') {
         return;
     }
     $file = pathinfo($object_file->filepath);
     // Skip if the pass through keyword is set
     if (preg_match('/' . $this->params->get('passthrough') . '_/', $file['filename'])) {
         return;
     }
     $image = new JImage();
     // Load the file
     $image->loadFile($object_file->filepath);
     // Get the properties
     $properties = $image->getImageFileProperties($object_file->filepath);
     // Skip if the width is less or equal to the required
     if ($properties->width <= $this->params->get('maxwidth')) {
         return;
     }
     // Get the image type
     if (preg_match('/jp(e)g/', mb_strtolower($properties->mime))) {
         $imageType = 'IMAGETYPE_JPEG';
     }
     if (preg_match('/gif/', mb_strtolower($properties->mime))) {
         $imageType = 'IMAGETYPE_GIF';
     }
     if (preg_match('/png/', mb_strtolower($properties->mime))) {
         $imageType = 'IMAGETYPE_PNG';
     }
     // Resize the image
     $image->resize($this->params->get('maxwidth'), '', false);
     // Overwrite the file
     $image->toFile($object_file->filepath, $imageType, array('quality' => $this->params->get('quality')));
     return $object_file;
 }
开发者ID:brianteeman,项目名称:imageUploaderHelper,代码行数:44,代码来源:uploader.php


示例17: onUserAfterSave

 /**
  * Save user profile data.
  *
  * @param   array    $data    Entered user data
  * @param   boolean  $isNew   True if this is a new user
  * @param   boolean  $result  True if saving the user worked
  * @param   string   $error   Error message
  *
  * @return  boolean
  */
 public function onUserAfterSave($data, $isNew, $result, $error)
 {
     // Only run in front-end.
     if (!JFactory::getApplication()->isSite()) {
         return true;
     }
     $userId = JArrayHelper::getValue($data, 'id', 0, 'int');
     $folder = $this->params->get('folder', '');
     $avatarFolder = JPATH_ROOT . '/' . $folder;
     // If the avatar folder doesn't exist, we don't do anything.
     if (!JFolder::exists($avatarFolder)) {
         return false;
     }
     $jinput = JFactory::getApplication()->input;
     $delete = $jinput->get('delete-avatar', '', 'word');
     if ($delete == 'yes') {
         $this->deleteAvatar($userId);
         return true;
     }
     if ($result && $userId > 0) {
         $files = $jinput->files->get('jform', array(), 'array');
         if (!isset($files['cmavatar']['cmavatar'])) {
             return false;
         }
         $file = $files['cmavatar']['cmavatar'];
         if (empty($file['name'])) {
             return true;
         }
         $fileTypes = explode('.', $file['name']);
         if (count($fileTypes) < 2) {
             // There seems to be no extension.
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
             return false;
         }
         array_shift($fileTypes);
         // Check if the file has an executable extension.
         $executable = array('php', 'js', 'exe', 'phtml', 'java', 'perl', 'py', 'asp', 'dll', 'go', 'ade', 'adp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'hta', 'ins', 'isp', 'jse', 'lib', 'mde', 'msc', 'msp', 'mst', 'pif', 'scr', 'sct', 'shb', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh');
         $check = array_intersect($fileTypes, $executable);
         if (!empty($check)) {
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
             return false;
         }
         $fileType = array_pop($fileTypes);
         $allowable = array_map('trim', explode(',', $this->params->get('allowed_extensions')));
         if ($fileType == '' || $fileType == false || !in_array($fileType, $allowable)) {
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
             return false;
         }
         $uploadMaxSize = $this->params->get('max_size', 0) * 1024 * 1024;
         $uploadMaxFileSize = $this->toBytes(ini_get('upload_max_filesize'));
         if ($file['error'] == 1 || $uploadMaxSize > 0 && $file['size'] > $uploadMaxSize || $uploadMaxFileSize > 0 && $file['size'] > $uploadMaxFileSize) {
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TOO_LARGE'));
             return false;
         }
         // Make the file name unique.
         $md5String = $userId . $file['name'] . JFactory::getDate();
         $avatarFileName = JFile::makeSafe(md5($md5String));
         if (empty($avatarFileName)) {
             // No file name after the name was cleaned by JFile::makeSafe.
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_NO_FILENAME'));
             return false;
         }
         $avatarPath = JPath::clean($avatarFolder . '/' . $avatarFileName . '.' . $this->extension);
         if (JFile::exists($avatarPath)) {
             // A file with this name already exists. It is almost impossible.
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_EXISTS'));
             return false;
         }
         // Start resizing the file.
         $avatar = new JImage($file['tmp_name']);
         $originalWidth = $avatar->getWidth();
         $originalHeight = $avatar->getHeight();
         $ratio = $originalWidth / $originalHeight;
         $maxWidth = (int) $this->params->get('width', 100);
         $maxHeight = (int) $this->params->get('height', 100);
         // Invalid value in the plugin configuration. Set avatar width to 100.
         if ($maxWidth <= 0) {
             $maxWidth = 100;
         }
         if ($maxHeight <= 0) {
             $maxHeight = 100;
         }
         if ($originalWidth > $maxWidth) {
             $ratio = $originalWidth / $originalHeight;
             $newWidth = $maxWidth;
             $newHeight = $newWidth / $ratio;
             if ($newHeight > $maxHeight) {
                 $ratio = $newWidth / $newHeight;
                 $newHeight = $maxHeight;
                 $newWidth = $newHeight * $ratio;
//.........这里部分代码省略.........
开发者ID:Harmageddon,项目名称:cmavatar,代码行数:101,代码来源:cmavatar.php


示例18: resizeImage

 /**
  * Resize an image.
  *
  * @param   string  $file    The name and location of the file
  * @param   string  $width   The new width of the image.
  * @param   string  $height  The new height of the image.
  *
  * @return   boolean  true if image resize successful, false otherwise.
  *
  * @since   3.2
  */
 public function resizeImage($file, $width, $height)
 {
     if ($template = $this->getTemplate()) {
         $app = JFactory::getApplication();
         $client = JApplicationHelper::getClientInfo($template->client_id);
         $relPath = base64_decode($file);
         $path = JPath::clean($client->path . '/templates/' . $template->element . '/' . $relPath);
         $JImage = new JImage($path);
         try {
             $image = $JImage->resize($width, $height, true, 1);
             $image->toFile($path);
             return true;
         } catch (Exception $e) {
             $app->enqueueMessage($e->getMessage(), 'error');
         }
     }
 }
开发者ID:brenot,项目名称:forumdesenvolvimento,代码行数:28,代码来源:template.php


示例19: isValid

 /**
  * Validate image type and extension.
  *
  * <code>
  * $myFile     = "/tmp/myfile.jpg";
  * $fileName   = "myfile.jpg";
  *
  * $validator = new Prism\File\Validator\Image($myFile, $fileName);
  *
  * if (!$validator->isValid()) {
  *     echo $validator->getMessage();
  * }
  * </code>
  *
  * @return bool
  */
 public function isValid()
 {
     if (!\JFile::exists($this->file)) {
         $this->message = \JText::sprintf('LIB_PRISM_ERROR_FILE_DOES_NOT_EXISTS', $this->file);
         return false;
     }
     $imageProperties = \JImage::getImageFileProperties($this->file);
     // Check mime type of the file
     if (false === array_search($imageProperties->mime, $this->mimeTypes)) {
         $this->message = \JText::_('LIB_PRISM_ERROR_FILE_TYPE');
         return false;
     }
     // Check file extension
     $ext = \JString::strtolower(\JFile::getExt($this->fileName));
     if (false === array_search($ext, $this->imageExtensions)) {
         $this->message = \JText::sprintf('LIB_PRISM_ERROR_FILE_EXTENSIONS', $ext);
         return false;
     }
     return true;
 }
开发者ID:pashakiz,项目名称:crowdf,代码行数:36,代码来源:Image.php


示例20: onUserAfterSave


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP JInput类代码示例发布时间:2022-05-23
下一篇:
PHP JHttpFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap