当前位置: 首页>>代码示例>>PHP>>正文


PHP JImage类代码示例

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


在下文中一共展示了JImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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() . '/logo@2x.png" 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


注:本文中的JImage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。