本文整理汇总了PHP中JImage::cropResize方法的典型用法代码示例。如果您正苦于以下问题:PHP JImage::cropResize方法的具体用法?PHP JImage::cropResize怎么用?PHP JImage::cropResize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JImage
的用法示例。
在下文中一共展示了JImage::cropResize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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";
}
}
示例2: _getThumbnail
/**
* Get the thumbnail path.
*
* @param string $image Path to source image
* @param string $size The thumbnail size. Ex: '500x400'
* @param string $folder The thumbnail folder
* @param string $filename The thumbnail file name
* @param integer quality The thumbnail quality
*
* @return string The thumbnail path
*
* @throws ArgumentException
* @throws InvalidArgumentException
*/
private static function _getThumbnail($image, $size = '550x460', $folder = null, $filename = null, $quality = 90)
{
jimport('joomla.filesystem.file');
require_once __DIR__ . '/libraries/phpthumb/ThumbLib.inc.php';
if (empty($image)) {
throw new ArgumentException(JText::_("MOD_SLIDESHOW_ERROR_ARGUMENT_IMAGE_EMPTY"));
}
if (empty($folder)) {
$folder = 'cache/mod_slideshow';
}
$folder = JPATH_SITE . '/' . $folder;
// Check or try to create folder
if (JFolder::exists($folder) || JFolder::create($folder)) {
// Desired thumbnail size
$size = explode('x', strtolower($size));
if (count($size) != 2) {
throw new InvalidArgumentException(JText::sprintf('MOD_SLIDESHOW_ERROR_ARGUMENT_SIZE_INVALID', $size));
}
// Generate thumb name
$filename = empty($filename) ? pathinfo($image, PATHINFO_FILENAME) : $filename;
$extension = pathinfo($image, PATHINFO_EXTENSION);
$filename = $filename . '.' . $extension;
$file = $folder . '/' . $filename;
$image = new JImage($image);
try {
$thumbnail = $image->cropResize($size[0], $size[1], false);
$thumbnail->toFile($folder . '/' . $filename);
} catch (Exception $e) {
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
/*$thumbnail = PhpThumbFactory::create($image);
$thumbnail->setoptions(array('jpegQuality' => $quality,'resizeUp' => true));
$thumbnail->adaptiveResize($size[0], $size[1]);
$thumbnail->save($file);*/
}
return str_replace(JPATH_SITE . '/', JUri::root(), $file);
}