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


PHP JImage::getImageFileProperties方法代码示例

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


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

示例1: 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:ForAEdesWeb,项目名称:AEW3,代码行数:66,代码来源:thumb.php

示例2: _resize


//.........这里部分代码省略.........
     list($orig_w, $orig_h) = getimagesize($absoluteImagePath);
     if (isset($opts['w'])) {
         if (stripos($opts['w'], '%') !== false) {
             $w = (int) ((double) str_replace('%', '', $opts['w']) / 100 * $orig_w);
         } else {
             $w = (int) $opts['w'];
         }
     }
     if (isset($opts['h'])) {
         if (stripos($opts['h'], '%') !== false) {
             $h = (int) ((double) str_replace('%', '', $opts['h']) / 100 * $orig_h);
         } else {
             $h = (int) $opts['h'];
         }
     }
     if (!isset($opts['w']) && !isset($opts['h'])) {
         list($w, $h) = array($orig_w, $orig_h);
     }
     //$filename = md5_file($absoluteImagePath);
     //$imageExt = JFile::getExt($absoluteImagePaths);
     $imageName = preg_replace('/\\.' . $ext . '$/', '', JFile::getName($absoluteImagePath));
     $imageNameNew = $imageName . '_w' . $w . 'xh' . $h;
     if (!empty($w) and !empty($h)) {
         $imageNameNew = $imageName . '_w' . $w . '_h' . $h . (isset($opts['crop']) && $opts['crop'] == true ? "_cp" : "") . (isset($opts['scale']) && $opts['scale'] == true ? "_sc" : "") . '_q' . $opts['quality'];
     } elseif (!empty($w)) {
         $imageNameNew = $imageName . '_w' . $w . '_q' . $opts['quality'];
     } elseif (!empty($h)) {
         $imageNameNew = $imageName . '_h' . $h . '_q' . $opts['quality'];
     } else {
         return false;
     }
     //$absoluteImagePathNew = str_replace($imageName.'.'.$ext, $imageNameNew.'.'.$ext, $absoluteImagePath);//JPath::clean(JPATH_ROOT.'/'.$relativePathNew);
     $absoluteImagePathNew = JPath::clean(JPATH_ROOT . '/' . $cacheFolder . $imageNameNew . '.' . $ext);
     $relativeImagePathNew = preg_replace('/\\\\/', '/', str_replace(JPATH_ROOT, "", $absoluteImagePathNew));
     if (JFile::exists($absoluteImagePathNew)) {
         $imageDateOrigin = filemtime($absoluteImagePath);
         $imageDateThumb = filemtime($absoluteImagePathNew);
         $clearCache = $imageDateOrigin > $imageDateThumb;
         if ($clearCache == false) {
             return $relativeImagePathNew;
         }
     }
     //echo $relativeImagePathNew;die;
     if ($this->imagick_process == 'jimage' && class_exists('JImage')) {
         // s2s Use Joomla JImage class (GD)
         if (empty($w)) {
             $w = 0;
         }
         if (empty($h)) {
             $h = 0;
         }
         //echo $imagePath;die;
         // Keep proportions if w or h is not defined
         list($width, $height) = getimagesize($absoluteImagePath);
         //echo $width.' '.$height;die;
         if (!$w) {
             $w = $h / $height * $width;
         }
         if (!$h) {
             $h = $w / $width * $height;
         }
         //echo $imagePath;die;
         //echo (JURI::root().$imagePath);die;
         // http://stackoverflow.com/questions/10842734/how-resize-image-in-joomla
         try {
             $image = new JImage();
             $image->loadFile($absoluteImagePath);
             //echo'<pre>';var_dump($image);die;
         } catch (Exception $e) {
             return str_replace(JPATH_ROOT, "", $absoluteImagePath);
             // "Attempting to load an image of unsupported type: image/x-ms-bmp"
         }
         if ($opts['crop'] === true) {
             $rw = $w;
             $rh = $h;
             if ($width / $height < $rw / $rh) {
                 $rw = $w;
                 $rh = $rw / $width * $height;
             } else {
                 $rh = $h;
                 $rw = $rh / $height * $width;
             }
             $resizedImage = $image->resize($rw, $rh)->crop($w, $h);
         } else {
             $resizedImage = $image->resize($w, $h);
         }
         $properties = JImage::getImageFileProperties($absoluteImagePath);
         // fix compression level must be 0 through 9 (in case of png)
         $quality = $opts['quality'];
         if ($properties->type == IMAGETYPE_PNG) {
             $quality = round(9 - $quality * 9 / 100);
             // 100 quality = 0 compression, 0 quality = 9 compression
         }
         //echo '<pre>';var_dump($properties);die;
         $resizedImage->toFile($absoluteImagePathNew, $properties->type, array('quality' => $quality));
     }
     //echo $relativeImagePathNew;die;
     # return cache file path
     return $relativeImagePathNew;
 }
开发者ID:sankam-nikolya,项目名称:lptt,代码行数:101,代码来源:cthimageresizer.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: 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

示例5: 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

示例6: 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

示例7: testGetImageFilePropertiesWithInvalidFile

 /**
  * Test the JImage::getImageFileProperties method without a valid image file.
  *
  * @return  void
  *
  * @expectedException  InvalidArgumentException
  * @since   11.3
  */
 public function testGetImageFilePropertiesWithInvalidFile()
 {
     JImage::getImageFileProperties(JPATH_TESTS . '/suite/joomla/image/stubs/bogus.image');
 }
开发者ID:rvsjoen,项目名称:joomla-platform,代码行数:12,代码来源:JImageTest.php

示例8: 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

示例9: isValid

 /**
  * Validate image size.
  *
  * <code>
  * $myFile     = "/tmp/myfile.jpg";
  *
  * $validator = new PrismFileValidatorImageSize($myFile);
  *
  * 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 the minimum width of the image.
     if ($this->minWidth > 0 and $imageProperties->width < $this->minWidth) {
         $this->message = \JText::sprintf('LIB_PRISM_ERROR_FILE_IMAGE_MIN_WIDTH', $this->minWidth);
         return false;
     }
     // Check the minimum height of the image.
     if ($this->minHeight > 0 and $imageProperties->height < $this->minHeight) {
         $this->message = \JText::sprintf('LIB_PRISM_ERROR_FILE_IMAGE_MIN_HEIGHT', $this->minHeight);
         return false;
     }
     // Check the maximum width of the image.
     if ($this->maxWidth > 0 and $imageProperties->width > $this->maxWidth) {
         $this->message = \JText::sprintf('LIB_PRISM_ERROR_FILE_IMAGE_MAX_WIDTH', $this->maxWidth);
         return false;
     }
     // Check the maximum height of the image.
     if ($this->maxHeight > 0 and $imageProperties->height > $this->maxHeight) {
         $this->message = \JText::sprintf('LIB_PRISM_ERROR_FILE_IMAGE_MAX_HEIGHT', $this->maxHeight);
         return false;
     }
     return true;
 }
开发者ID:ITPrism,项目名称:SocialCommunityDistribution,代码行数:44,代码来源:Size.php

示例10: getimagesize

 $imageinfo = getimagesize($image['tmp_name']);
 $mime_types = $sconfig->mime_types;
 $okMIMETypes = $mime_types;
 $validFileTypes = explode(",", $okMIMETypes);
 if (is_int($imageinfo[0]) || is_int($imageinfo[1]) || in_array($imageinfo['mime'], $validFileTypes)) {
     $image['name'] = preg_replace("/[^A-Za-z.0-9]/i", "-", $image['name']);
     $newName = 'profile-' . $uid . '-' . $time . '-' . $image['name'];
     $newName2 = 'profile-x-' . $uid . '-' . $time . '-' . $image['name'];
     $uploadPath = $base_path . $uid . DS . $newName;
     $uploadPath2 = $base_path . $uid . DS . $newName2;
     $stampPath = JPATH_COMPONENT . DS . 'assets' . DS . 'images' . DS . 'stamp.png';
     $file_name = $newName2;
     JFile::upload($image['tmp_name'], $uploadPath);
     ####################
     $image = new JImage($uploadPath);
     $properties = JImage::getImageFileProperties($uploadPath);
     $resizedImage = $image->resize('250', '250', true);
     $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($uploadPath, $type);
     //create image .....
     //echo 'creem imaginea<br />';
     watermark_image($uploadPath, $uploadPath2, $mime);
     ####################
     ######adaugare in baza de date
开发者ID:grchis,项目名称:Site-Auto,代码行数:31,代码来源:default_0.php

示例11: resizeImage

 /** resize images */
 public static function resizeImage($originalPath, $thumbPath, $width, $height)
 {
     $imageObj = new JImage($originalPath);
     $properties = JImage::getImageFileProperties($originalPath);
     $resizedImage = $imageObj->resize($width, $height, true);
     $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($thumbPath, $type);
 }
开发者ID:Tommar,项目名称:vino,代码行数:16,代码来源:generator.php

示例12: prepareImageProperties

 protected function prepareImageProperties($file)
 {
     $imageProperties = \JImage::getImageFileProperties($file);
     $properties = array('width' => $imageProperties->width, 'height' => $imageProperties->height, 'mime' => $imageProperties->mime, 'filesize' => $imageProperties->filesize);
     return $properties;
 }
开发者ID:bellodox,项目名称:PrismLibrary,代码行数:6,代码来源:Image.php

示例13: getFileProperties

 public static function getFileProperties($source)
 {
     return JImage::getImageFileProperties($source);
 }
开发者ID:ErickLopez76,项目名称:offiria,代码行数:4,代码来源:ximage.php

示例14: save


//.........这里部分代码省略.........
         }
     }
     $path = '';
     $path_hover = '';
     jimport('joomla.filesystem.file');
     $imageType = null;
     $imageMimeType = null;
     $imageSize = null;
     $image_hoverType = null;
     $image_hoverMimeType = null;
     $image_hoverSize = null;
     // Create original image with new name (upload from client)
     if (count($images) && !empty($images['tmp_name'])) {
         // Get image file type
         $imageType = JFile::getExt($images['name']);
         $imageType = strtolower($imageType);
         // Get image's mime type
         $imageMimeType = $images['type'];
         // Get image's size
         $imageSize = $images['size'];
         $path = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR;
         $path .= $data->alias . '-' . $data->id . '_o';
         $path .= '.' . JFile::getExt($images['name']);
         if ($input->getCmd('task') == 'save2copy' && $input->getInt('id')) {
             $image_data['url_server'] = null;
         }
     } elseif (isset($image_data['url_server']) && !empty($image_data['url_server'])) {
         // Create original image with new name (upload from server)
         // Get image file type
         $imageType = JFile::getExt($image_data['url_server']);
         $imageType = strtolower($imageType);
         // Get image's mime type
         $imageObj->loadFile(JPATH_ROOT . DIRECTORY_SEPARATOR . $image_data['url_server']);
         $imageMimeType = $imageObj->getImageFileProperties($imageObj->getPath());
         $imageMimeType = $imageMimeType->mime;
         // Get image's size
         $imageSize = $imageMimeType->filesize;
         $path = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR;
         $path .= $data->alias . '-' . $data->id . '_o';
         $path .= '.' . JFile::getExt($image_data['url_server']);
     }
     // Create original image hover with new name (upload from client)
     if (count($images_hover) && !empty($images_hover['tmp_name'])) {
         // Get image hover file type
         $image_hoverType = JFile::getExt($images_hover['name']);
         $image_hoverType = strtolower($image_hoverType);
         // Get image hover's mime type
         $image_hoverMimeType = $images_hover['type'];
         // Get image's size
         $image_hoverSize = $images_hover['size'];
         $path_hover = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR;
         $path_hover .= $data->alias . '-' . $data->id . '-h_o';
         $path_hover .= '.' . JFile::getExt($images_hover['name']);
         if ($input->getCmd('task') == 'save2copy' && $input->getInt('id')) {
             $image_data['url_hover_server'] = null;
         }
     } elseif (isset($image_data['url_hover_server']) && !empty($image_data['url_hover_server'])) {
         // Create original image with new name (upload from server)
         // Get image hover file type
         $image_hoverType = JFile::getExt($image_data['url_hover_server']);
         $image_hoverType = strtolower($image_hoverType);
         // Get image hover's mime type
         $imageObj->loadFile(JPATH_ROOT . DIRECTORY_SEPARATOR . $image_data['url_hover_server']);
         $image_hoverMimeType = $imageObj->getImageFileProperties($imageObj->getPath());
         $image_hoverMimeType = $image_hoverMimeType->mime;
         // Get image hover's size
开发者ID:templaza,项目名称:tz_portfolio_plus,代码行数:67,代码来源:image.php

示例15: getInput

 /**
  * Method to get the list of input[type="file"]
  *
  * @return  string  The field input markup.
  *
  * @since   11.1
  */
 protected function getInput()
 {
     $output = '';
     $params = JComponentHelper::getParams('com_jea');
     $imgUploadNumber = $params->get('img_upload_number', 3);
     for ($i = 0; $i < $imgUploadNumber; $i++) {
         $output .= '<input type="file" name="newimages[]" value=""  size="30" class="fltnone" /> <br />';
     }
     $output .= "\n";
     //alert & return if GD library for PHP is not enabled
     if (!extension_loaded('gd')) {
         $output .= '<strong>WARNING: </strong>The <a href="http://php.net/manual/en/book.image.php" target="_blank">GD library for PHP</a> was not found. Ensure to install it';
         return $output;
     }
     if (is_string($this->value)) {
         $images = (array) json_decode($this->value);
     } else {
         $images = (array) $this->value;
         foreach ($images as $k => $image) {
             $images[$k] = (object) $image;
         }
     }
     $propertyId = $this->form->getValue('id');
     $baseURL = JURI::root(true);
     $imgBaseURL = $baseURL . '/images/com_jea/images/' . $propertyId;
     $imgBasePath = JPATH_ROOT . DS . 'images' . DS . 'com_jea' . DS . 'images' . DS . $propertyId;
     if (!empty($images)) {
         $output .= "<ul class=\"gallery\">\n";
         foreach ($images as $k => $image) {
             $imgPath = $imgBasePath . DS . $image->name;
             try {
                 $infos = JImage::getImageFileProperties($imgPath);
             } catch (Exception $e) {
                 $output .= "<li>Recorded Image " . $image->name . " cannot be accessed</li>\n";
                 continue;
             }
             $thumbName = 'thumb-admin-' . $image->name;
             // Create the thumbnail
             if (!file_exists($imgBasePath . DS . $thumbName)) {
                 try {
                     // This is where the JImage will be used, so only create it here
                     $JImage = new JImage($imgPath);
                     $thumb = $JImage->resize(150, 90);
                     $thumb->crop(150, 90, 0, 0);
                     $thumb->toFile($imgBasePath . DS . $thumbName);
                     // To avoid memory overconsumption, destroy the JImage now that we don't need it anymore
                     if (method_exists($JImage, 'destroy')) {
                         $JImage->destroy();
                         $thumb->destroy();
                     } else {
                         // There is no destroy method on Jplatform < 12.3 (Joomla 2.5) and the handle property is protected.
                         // We have to hack the JImage class to destroy the image resource
                         $prop = new ReflectionProperty('JImage', 'handle');
                         $prop->setAccessible(true);
                         $JImageHandle = $prop->getValue($JImage);
                         $thumbHandle = $prop->getValue($thumb);
                         if (is_resource($JImageHandle)) {
                             imagedestroy($JImageHandle);
                         }
                         if (is_resource($thumbHandle)) {
                             imagedestroy($thumbHandle);
                         }
                     }
                 } catch (Exception $e) {
                     $output .= "<li>Thumbnail for " . $image->name . " cannot be generated</li>\n";
                     continue;
                 }
             }
             $thumbUrl = $imgBaseURL . '/' . $thumbName;
             $url = $imgBaseURL . '/' . $image->name;
             $weight = round($infos->bits / 1024, 1);
             // Ko
             $output .= "<li class=\"item-{$k}\">\n" . "<a href=\"{$url}\" title=\"Zoom\" class=\"imgLink modal\" rel=\"{handler: 'image'}\"><img src=\"{$thumbUrl}\" alt=\"{$image->name}\" /></a>\n" . "<div class=\"imgInfos\">\n" . $image->name . "<br />\n" . JText::_('COM_JEA_WIDTH') . ' : ' . $infos->width . ' px' . "<br />\n" . JText::_('COM_JEA_HEIGHT') . ' : ' . $infos->height . ' px' . "<br />\n" . "</div>\n" . "<div class=\"imgTools\">\n" . '  <a class="img-move-up" title="' . JText::_('JLIB_HTML_MOVE_UP') . '"><img src="' . $baseURL . '/media/com_jea/images/sort_asc.png' . '" alt="Move up" /></a>' . '  <a class="img-move-down" title="' . JText::_('JLIB_HTML_MOVE_DOWN') . '"><img src="' . $baseURL . '/media/com_jea/images/sort_desc.png' . '" alt="Move down" /></a>' . '  <a class="delete-img" title="' . JText::_('JACTION_DELETE') . '"><img src="' . $baseURL . '/media/com_jea/images/media_trash.png' . '" alt="Delete" /></a>' . "</div>\n" . "<div class=\"clr\"></div>\n" . '<label for="' . $this->id . $k . 'title">' . JText::_('JGLOBAL_TITLE') . '</label><input id="' . $this->id . $k . 'title" type="text" name="' . $this->name . '[' . $k . '][title]" value="' . $image->title . '" size="20"/><br />' . '<label for="' . $this->id . $k . 'desc">' . JText::_('JGLOBAL_DESCRIPTION') . '</label><input id="' . $this->id . $k . 'desc" type="text" name="' . $this->name . '[' . $k . '][description]" value="' . $image->description . '" size="40"/>' . '<input type="hidden" name="' . $this->name . '[' . $k . '][name]" value="' . $image->name . '" />' . "<div class=\"clr\"></div>\n" . "</li>\n";
         }
         $output .= "</ul>\n";
         // Add javascript behavior
         JHtml::_('behavior.modal');
         JFactory::getDocument()->addScriptDeclaration("\n                window.addEvent('domready', function() {\n                    var sortOptions = {\n                        transition: Fx.Transitions.Back.easeInOut,\n                        duration: 700,\n                        mode: 'vertical',\n                        onComplete: function() {\n                           mySort.rearrangeDOM()\n                        }\n                    };\n\n                    var mySort = new Fx.Sort(\$\$('ul.gallery li'), sortOptions);\n\n                    \$\$('a.delete-img').each(function(item) {\n                        item.addEvent('click', function() {\n                            this.getParent('li').destroy();\n                            mySort = new Fx.Sort(\$\$('ul.gallery li'), sortOptions);\n                        });\n                    });\n\n                    \$\$('a.img-move-up').each(function(item) {\n                        item.addEvent('click', function() {\n                            var activeLi = this.getParent('li');\n                            if (activeLi.getPrevious()) {\n                                mySort.swap(activeLi, activeLi.getPrevious());\n                            } else if (this.getParent('ul').getChildren().length > 1 ) {\n                                // Swap with the last element\n                            \tmySort.swap(activeLi, this.getParent('ul').getLast('li'));\n                            }\n                        });\n                    });\n\n                     \$\$('a.img-move-down').each(function(item) {\n                        item.addEvent('click', function() {\n                            var activeLi = this.getParent('li');\n                            if (activeLi.getNext()) {\n                                mySort.swap(activeLi, activeLi.getNext());\n                            } else if (this.getParent('ul').getChildren().length > 1 ) {\n                                // Swap with the first element\n                            \tmySort.swap(activeLi, this.getParent('ul').getFirst('li'));\n                            }\n                        });\n                    });\n\n                })");
     }
     return $output;
 }
开发者ID:Cloudum,项目名称:com_jea,代码行数:88,代码来源:gallery.php


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