mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Upgrade PHP thumb and watermarks for images added
This commit is contained in:
parent
92fc540ac6
commit
cadadb29b9
@ -1791,8 +1791,6 @@ class e_parse
|
|||||||
|
|
||||||
if($raw) $url = $this->createConstants($url, 'mix');
|
if($raw) $url = $this->createConstants($url, 'mix');
|
||||||
|
|
||||||
// echo "<br />".$url;
|
|
||||||
|
|
||||||
$thurl = ($full ? SITEURL : e_HTTP).'thumb.php?src='.$url.'&';
|
$thurl = ($full ? SITEURL : e_HTTP).'thumb.php?src='.$url.'&';
|
||||||
|
|
||||||
if(vartrue($options['aw']) || vartrue($options['ah']))
|
if(vartrue($options['aw']) || vartrue($options['ah']))
|
||||||
@ -1804,7 +1802,14 @@ class e_parse
|
|||||||
if(!vartrue($options['w']) && !vartrue($options['h'])) $options['w'] = 100;
|
if(!vartrue($options['w']) && !vartrue($options['h'])) $options['w'] = 100;
|
||||||
$thurl .= 'w='.((integer) vartrue($options['w'], 0)).'&h='.((integer) vartrue($options['h'], 0));
|
$thurl .= 'w='.((integer) vartrue($options['w'], 0)).'&h='.((integer) vartrue($options['h'], 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(vartrue($options['wm']))//TODO remove from URL. set session.
|
||||||
|
{
|
||||||
|
$thurl .= "&wm=".$this->replaceConstants($options['wm'],'abs');
|
||||||
|
}
|
||||||
|
|
||||||
|
// echo "<br /><br />".$thurl;
|
||||||
|
|
||||||
return $thurl;
|
return $thurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +149,73 @@ class GdThumb extends ThumbBase
|
|||||||
##############################
|
##############################
|
||||||
# ----- API FUNCTIONS ------ #
|
# ----- API FUNCTIONS ------ #
|
||||||
##############################
|
##############################
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pad an image to desired dimensions if required
|
||||||
|
*
|
||||||
|
* Moves the image into the center and fills the rest with $color
|
||||||
|
*
|
||||||
|
* Author: Blake Kus <http://blakek.us>
|
||||||
|
*
|
||||||
|
* @param mixed $width
|
||||||
|
* @param mixed $height
|
||||||
|
* @param mixed $color
|
||||||
|
*/
|
||||||
|
public function pad ($width, $height, $color=array(255, 255, 255))
|
||||||
|
{
|
||||||
|
// no resize - woohoo!
|
||||||
|
if($width == $this->currentDimensions['width'] && $height == $this->currentDimensions['height']){
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the working image
|
||||||
|
if (function_exists('imagecreatetruecolor'))
|
||||||
|
{
|
||||||
|
$this->workingImage = imagecreatetruecolor($width, $height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->workingImage = imagecreate($width, $height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the fill color
|
||||||
|
$fillColor = imagecolorallocate(
|
||||||
|
$this->workingImage,
|
||||||
|
$color[0],
|
||||||
|
$color[1],
|
||||||
|
$color[2]
|
||||||
|
);
|
||||||
|
|
||||||
|
// fill our working image with the fill color
|
||||||
|
imagefill(
|
||||||
|
$this->workingImage,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$fillColor
|
||||||
|
);
|
||||||
|
|
||||||
|
// copy the image into the center of our working image
|
||||||
|
imagecopyresampled
|
||||||
|
(
|
||||||
|
$this->workingImage,
|
||||||
|
$this->oldImage,
|
||||||
|
intval(($width-$this->currentDimensions['width'])/2),
|
||||||
|
intval(($height-$this->currentDimensions['height'])/2),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$this->currentDimensions['width'],
|
||||||
|
$this->currentDimensions['height'],
|
||||||
|
$this->currentDimensions['width'],
|
||||||
|
$this->currentDimensions['height']
|
||||||
|
);
|
||||||
|
|
||||||
|
// update all the variables and resources to be correct
|
||||||
|
$this->oldImage = $this->workingImage;
|
||||||
|
$this->currentDimensions['width'] = $width;
|
||||||
|
$this->currentDimensions['height'] = $height;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes an image to be no larger than $maxWidth or $maxHeight
|
* Resizes an image to be no larger than $maxWidth or $maxHeight
|
||||||
@ -237,14 +304,19 @@ class GdThumb extends ThumbBase
|
|||||||
public function adaptiveResize ($width, $height)
|
public function adaptiveResize ($width, $height)
|
||||||
{
|
{
|
||||||
// make sure our arguments are valid
|
// make sure our arguments are valid
|
||||||
if (!is_numeric($width) || $width == 0)
|
if ((!is_numeric($width) || $width == 0) && (!is_numeric($height) || $height == 0))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('$width must be numeric and greater than zero');
|
throw new InvalidArgumentException('$width and $height must be numeric and greater than zero');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($height) || $height == 0)
|
if (!is_numeric($width) || $width == 0)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('$height must be numeric and greater than zero');
|
$width = ( $height * $this->currentDimensions['width'] ) / $this->currentDimensions['height'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_numeric($height) || $height == 0)
|
||||||
|
{
|
||||||
|
$height = ( $width * $this->currentDimensions['height'] ) / $this->currentDimensions['width'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we're not exceeding our image size if we're not supposed to
|
// make sure we're not exceeding our image size if we're not supposed to
|
||||||
@ -324,7 +396,289 @@ class GdThumb extends ThumbBase
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adaptively Resizes the Image and Crops Using a Percentage
|
||||||
|
*
|
||||||
|
* This function attempts to get the image to as close to the provided dimensions as possible, and then crops the
|
||||||
|
* remaining overflow using a provided percentage to get the image to be the size specified.
|
||||||
|
*
|
||||||
|
* The percentage mean different things depending on the orientation of the original image.
|
||||||
|
*
|
||||||
|
* For Landscape images:
|
||||||
|
* ---------------------
|
||||||
|
*
|
||||||
|
* A percentage of 1 would crop the image all the way to the left, which would be the same as
|
||||||
|
* using adaptiveResizeQuadrant() with $quadrant = 'L'
|
||||||
|
*
|
||||||
|
* A percentage of 50 would crop the image to the center which would be the same as using
|
||||||
|
* adaptiveResizeQuadrant() with $quadrant = 'C', or even the original adaptiveResize()
|
||||||
|
*
|
||||||
|
* A percentage of 100 would crop the image to the image all the way to the right, etc, etc.
|
||||||
|
* Note that you can use any percentage between 1 and 100.
|
||||||
|
*
|
||||||
|
* For Portrait images:
|
||||||
|
* --------------------
|
||||||
|
*
|
||||||
|
* This works the same as for Landscape images except that a percentage of 1 means top and 100 means bottom
|
||||||
|
*
|
||||||
|
* @param int $maxWidth
|
||||||
|
* @param int $maxHeight
|
||||||
|
* @param int $percent
|
||||||
|
* @return GdThumb
|
||||||
|
*/
|
||||||
|
public function adaptiveResizePercent ($width, $height, $percent = 50)
|
||||||
|
{
|
||||||
|
// make sure our arguments are valid
|
||||||
|
if (!is_numeric($width) || $width == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('$width must be numeric and greater than zero');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_numeric($height) || $height == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('$height must be numeric and greater than zero');
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we're not exceeding our image size if we're not supposed to
|
||||||
|
if ($this->options['resizeUp'] === false)
|
||||||
|
{
|
||||||
|
$this->maxHeight = (intval($height) > $this->currentDimensions['height']) ? $this->currentDimensions['height'] : $height;
|
||||||
|
$this->maxWidth = (intval($width) > $this->currentDimensions['width']) ? $this->currentDimensions['width'] : $width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->maxHeight = intval($height);
|
||||||
|
$this->maxWidth = intval($width);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->calcImageSizeStrict($this->currentDimensions['width'], $this->currentDimensions['height']);
|
||||||
|
|
||||||
|
// resize the image to be close to our desired dimensions
|
||||||
|
$this->resize($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
|
||||||
|
|
||||||
|
// reset the max dimensions...
|
||||||
|
if ($this->options['resizeUp'] === false)
|
||||||
|
{
|
||||||
|
$this->maxHeight = (intval($height) > $this->currentDimensions['height']) ? $this->currentDimensions['height'] : $height;
|
||||||
|
$this->maxWidth = (intval($width) > $this->currentDimensions['width']) ? $this->currentDimensions['width'] : $width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->maxHeight = intval($height);
|
||||||
|
$this->maxWidth = intval($width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the working image
|
||||||
|
if (function_exists('imagecreatetruecolor'))
|
||||||
|
{
|
||||||
|
$this->workingImage = imagecreatetruecolor($this->maxWidth, $this->maxHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->workingImage = imagecreate($this->maxWidth, $this->maxHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->preserveAlpha();
|
||||||
|
|
||||||
|
$cropWidth = $this->maxWidth;
|
||||||
|
$cropHeight = $this->maxHeight;
|
||||||
|
$cropX = 0;
|
||||||
|
$cropY = 0;
|
||||||
|
|
||||||
|
// Crop the rest of the image using the quadrant
|
||||||
|
|
||||||
|
if ($percent > 100) {
|
||||||
|
$percent = 100;
|
||||||
|
} elseif ($percent < 1) {
|
||||||
|
$percent = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->currentDimensions['width'] > $this->maxWidth)
|
||||||
|
{
|
||||||
|
// Image is landscape
|
||||||
|
$maxCropX = $this->currentDimensions['width'] - $this->maxWidth;
|
||||||
|
$cropX = intval(($percent / 100) * $maxCropX);
|
||||||
|
|
||||||
|
} elseif ($this->currentDimensions['height'] > $this->maxHeight)
|
||||||
|
{
|
||||||
|
// Image is portrait
|
||||||
|
$maxCropY = $this->currentDimensions['height'] - $this->maxHeight;
|
||||||
|
$cropY = intval(($percent / 100) * $maxCropY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
imagecopyresampled
|
||||||
|
(
|
||||||
|
$this->workingImage,
|
||||||
|
$this->oldImage,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$cropX,
|
||||||
|
$cropY,
|
||||||
|
$cropWidth,
|
||||||
|
$cropHeight,
|
||||||
|
$cropWidth,
|
||||||
|
$cropHeight
|
||||||
|
);
|
||||||
|
|
||||||
|
// update all the variables and resources to be correct
|
||||||
|
$this->oldImage = $this->workingImage;
|
||||||
|
$this->currentDimensions['width'] = $this->maxWidth;
|
||||||
|
$this->currentDimensions['height'] = $this->maxHeight;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Adaptively Resizes the Image and Crops Using a Quadrant
|
||||||
|
*
|
||||||
|
* This function attempts to get the image to as close to the provided dimensions as possible, and then crops the
|
||||||
|
* remaining overflow using the quadrant to get the image to be the size specified.
|
||||||
|
*
|
||||||
|
* The quadrants available are Top, Bottom, Center, Left, and Right:
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* +---+---+---+
|
||||||
|
* | | T | |
|
||||||
|
* +---+---+---+
|
||||||
|
* | L | C | R |
|
||||||
|
* +---+---+---+
|
||||||
|
* | | B | |
|
||||||
|
* +---+---+---+
|
||||||
|
*
|
||||||
|
* Note that if your image is Landscape and you choose either of the Top or Bottom quadrants (which won't
|
||||||
|
* make sence since only the Left and Right would be available, then the Center quadrant will be used
|
||||||
|
* to crop. This would have exactly the same result as using adaptiveResize().
|
||||||
|
* The same goes if your image is portrait and you choose either the Left or Right quadrants.
|
||||||
|
*
|
||||||
|
* @param int $maxWidth
|
||||||
|
* @param int $maxHeight
|
||||||
|
* @param string $quadrant T, B, C, L, R
|
||||||
|
* @return GdThumb
|
||||||
|
*/
|
||||||
|
public function adaptiveResizeQuadrant ($width, $height, $quadrant = 'C')
|
||||||
|
{
|
||||||
|
// make sure our arguments are valid
|
||||||
|
if (!is_numeric($width) || $width == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('$width must be numeric and greater than zero');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_numeric($height) || $height == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('$height must be numeric and greater than zero');
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we're not exceeding our image size if we're not supposed to
|
||||||
|
if ($this->options['resizeUp'] === false)
|
||||||
|
{
|
||||||
|
$this->maxHeight = (intval($height) > $this->currentDimensions['height']) ? $this->currentDimensions['height'] : $height;
|
||||||
|
$this->maxWidth = (intval($width) > $this->currentDimensions['width']) ? $this->currentDimensions['width'] : $width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->maxHeight = intval($height);
|
||||||
|
$this->maxWidth = intval($width);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->calcImageSizeStrict($this->currentDimensions['width'], $this->currentDimensions['height']);
|
||||||
|
|
||||||
|
// resize the image to be close to our desired dimensions
|
||||||
|
$this->resize($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
|
||||||
|
|
||||||
|
// reset the max dimensions...
|
||||||
|
if ($this->options['resizeUp'] === false)
|
||||||
|
{
|
||||||
|
$this->maxHeight = (intval($height) > $this->currentDimensions['height']) ? $this->currentDimensions['height'] : $height;
|
||||||
|
$this->maxWidth = (intval($width) > $this->currentDimensions['width']) ? $this->currentDimensions['width'] : $width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->maxHeight = intval($height);
|
||||||
|
$this->maxWidth = intval($width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the working image
|
||||||
|
if (function_exists('imagecreatetruecolor'))
|
||||||
|
{
|
||||||
|
$this->workingImage = imagecreatetruecolor($this->maxWidth, $this->maxHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->workingImage = imagecreate($this->maxWidth, $this->maxHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->preserveAlpha();
|
||||||
|
|
||||||
|
$cropWidth = $this->maxWidth;
|
||||||
|
$cropHeight = $this->maxHeight;
|
||||||
|
$cropX = 0;
|
||||||
|
$cropY = 0;
|
||||||
|
|
||||||
|
// Crop the rest of the image using the quadrant
|
||||||
|
|
||||||
|
if ($this->currentDimensions['width'] > $this->maxWidth)
|
||||||
|
{
|
||||||
|
// Image is landscape
|
||||||
|
switch ($quadrant) {
|
||||||
|
case 'L':
|
||||||
|
$cropX = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'R':
|
||||||
|
$cropX = intval(($this->currentDimensions['width'] - $this->maxWidth));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'C':
|
||||||
|
default:
|
||||||
|
$cropX = intval(($this->currentDimensions['width'] - $this->maxWidth) / 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} elseif ($this->currentDimensions['height'] > $this->maxHeight)
|
||||||
|
{
|
||||||
|
// Image is portrait
|
||||||
|
switch ($quadrant) {
|
||||||
|
case 'T':
|
||||||
|
$cropY = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'B':
|
||||||
|
$cropY = intval(($this->currentDimensions['height'] - $this->maxHeight));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'C':
|
||||||
|
default:
|
||||||
|
$cropY = intval(($this->currentDimensions['height'] - $this->maxHeight) / 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
imagecopyresampled
|
||||||
|
(
|
||||||
|
$this->workingImage,
|
||||||
|
$this->oldImage,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$cropX,
|
||||||
|
$cropY,
|
||||||
|
$cropWidth,
|
||||||
|
$cropHeight,
|
||||||
|
$cropWidth,
|
||||||
|
$cropHeight
|
||||||
|
);
|
||||||
|
|
||||||
|
// update all the variables and resources to be correct
|
||||||
|
$this->oldImage = $this->workingImage;
|
||||||
|
$this->currentDimensions['width'] = $this->maxWidth;
|
||||||
|
$this->currentDimensions['height'] = $this->maxHeight;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes an image by a given percent uniformly
|
* Resizes an image by a given percent uniformly
|
||||||
*
|
*
|
||||||
@ -552,6 +906,41 @@ class GdThumb extends ThumbBase
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a filter to the image
|
||||||
|
*
|
||||||
|
* @param int $filter
|
||||||
|
* @return GdThumb
|
||||||
|
*/
|
||||||
|
public function imageFilter ($filter, $arg1 = false, $arg2 = false, $arg3 = false, $arg4 = false)
|
||||||
|
{
|
||||||
|
if (!is_numeric($filter))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('$filter must be numeric');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('imagefilter'))
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Your version of GD does not support image filters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
if ( $arg1 === false ) $result = imagefilter($this->oldImage, $filter);
|
||||||
|
else if ( $arg2 === false ) $result = imagefilter($this->oldImage, $filter, $arg1);
|
||||||
|
else if ( $arg3 === false ) $result = imagefilter($this->oldImage, $filter, $arg1, $arg2);
|
||||||
|
else if ( $arg4 === false ) $result = imagefilter($this->oldImage, $filter, $arg1, $arg2, $arg3);
|
||||||
|
else $result = imagefilter($this->oldImage, $filter, $arg1, $arg2, $arg3, $arg4);
|
||||||
|
|
||||||
|
if (!$result)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('GD imagefilter failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->workingImage = $this->oldImage;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows an image
|
* Shows an image
|
||||||
*
|
*
|
||||||
@ -564,12 +953,18 @@ class GdThumb extends ThumbBase
|
|||||||
*/
|
*/
|
||||||
public function show ($rawData = false)
|
public function show ($rawData = false)
|
||||||
{
|
{
|
||||||
if (headers_sent())
|
if (headers_sent() && php_sapi_name() != 'cli')
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Cannot show image, headers have already been sent');
|
throw new RuntimeException('Cannot show image, headers have already been sent');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($this->format)
|
// When the interlace option equals true or false call imageinterlace else leave it to default
|
||||||
|
if ($this->options['interlace'] === true)
|
||||||
|
imageinterlace($this->oldImage, 1);
|
||||||
|
elseif ($this->options['interlace'] === false)
|
||||||
|
imageinterlace($this->oldImage, 0);
|
||||||
|
|
||||||
|
switch ($this->format)
|
||||||
{
|
{
|
||||||
case 'GIF':
|
case 'GIF':
|
||||||
if ($rawData === false)
|
if ($rawData === false)
|
||||||
@ -663,7 +1058,13 @@ class GdThumb extends ThumbBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($format)
|
// When the interlace option equals true or false call imageinterlace else leave it to default
|
||||||
|
if ($this->options['interlace'] === true)
|
||||||
|
imageinterlace($this->oldImage, 1);
|
||||||
|
elseif ($this->options['interlace'] === false)
|
||||||
|
imageinterlace($this->oldImage, 0);
|
||||||
|
|
||||||
|
switch ($format)
|
||||||
{
|
{
|
||||||
case 'GIF':
|
case 'GIF':
|
||||||
imagegif($this->oldImage, $fileName);
|
imagegif($this->oldImage, $fileName);
|
||||||
@ -713,7 +1114,8 @@ class GdThumb extends ThumbBase
|
|||||||
'preserveAlpha' => true,
|
'preserveAlpha' => true,
|
||||||
'alphaMaskColor' => array (255, 255, 255),
|
'alphaMaskColor' => array (255, 255, 255),
|
||||||
'preserveTransparency' => true,
|
'preserveTransparency' => true,
|
||||||
'transparencyMaskColor' => array (0, 0, 0)
|
'transparencyMaskColor' => array (0, 0, 0),
|
||||||
|
'interlace' => null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// otherwise, let's use what we've got already
|
// otherwise, let's use what we've got already
|
||||||
|
@ -1,44 +1,44 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PhpThumb Library Definition File
|
* PhpThumb Library Definition File
|
||||||
*
|
*
|
||||||
* This file contains the definitions for the PhpThumb class.
|
* This file contains the definitions for the PhpThumb class.
|
||||||
*
|
*
|
||||||
* PHP Version 5 with GD 2.0+
|
* PHP Version 5 with GD 2.0+
|
||||||
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
|
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
|
||||||
* Copyright (c) 2009, Ian Selby/Gen X Design
|
* Copyright (c) 2009, Ian Selby/Gen X Design
|
||||||
*
|
*
|
||||||
* Author(s): Ian Selby <ian@gen-x-design.com>
|
* Author(s): Ian Selby <ian@gen-x-design.com>
|
||||||
*
|
*
|
||||||
* Licensed under the MIT License
|
* Licensed under the MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Ian Selby <ian@gen-x-design.com>
|
* @author Ian Selby <ian@gen-x-design.com>
|
||||||
* @copyright Copyright (c) 2009 Gen X Design
|
* @copyright Copyright (c) 2009 Gen X Design
|
||||||
* @link http://phpthumb.gxdlabs.com
|
* @link http://phpthumb.gxdlabs.com
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
* @version 3.0
|
* @version 3.0
|
||||||
* @package PhpThumb
|
* @package PhpThumb
|
||||||
* @filesource $URL$
|
* @filesource
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PhpThumb Object
|
* PhpThumb Object
|
||||||
*
|
*
|
||||||
* This singleton object is essentially a function library that helps with core validation
|
* This singleton object is essentially a function library that helps with core validation
|
||||||
* and loading of the core classes and plugins. There isn't really any need to access it directly,
|
* and loading of the core classes and plugins. There isn't really any need to access it directly,
|
||||||
* unless you're developing a plugin and need to take advantage of any of the functionality contained
|
* unless you're developing a plugin and need to take advantage of any of the functionality contained
|
||||||
* within.
|
* within.
|
||||||
*
|
*
|
||||||
* If you're not familiar with singleton patterns, here's how you get an instance of this class (since you
|
* If you're not familiar with singleton patterns, here's how you get an instance of this class (since you
|
||||||
* can't create one via the new keyword):
|
* can't create one via the new keyword):
|
||||||
* <code>$pt = PhpThumb::getInstance();</code>
|
* <code>$pt = PhpThumb::getInstance();</code>
|
||||||
*
|
*
|
||||||
* It's that simple! Outside of that, there's no need to modify anything within this class, unless you're doing
|
* It's that simple! Outside of that, there's no need to modify anything within this class, unless you're doing
|
||||||
* some crazy customization... then knock yourself out! :)
|
* some crazy customization... then knock yourself out! :)
|
||||||
*
|
*
|
||||||
* @package PhpThumb
|
* @package PhpThumb
|
||||||
* @subpackage Core
|
* @subpackage Core
|
||||||
*/
|
*/
|
||||||
@ -46,36 +46,36 @@ class PhpThumb
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Instance of self
|
* Instance of self
|
||||||
*
|
*
|
||||||
* @var object PhpThumb
|
* @var object PhpThumb
|
||||||
*/
|
*/
|
||||||
protected static $_instance;
|
protected static $_instance;
|
||||||
/**
|
/**
|
||||||
* The plugin registry
|
* The plugin registry
|
||||||
*
|
*
|
||||||
* This is where all plugins to be loaded are stored. Data about the plugin is
|
* This is where all plugins to be loaded are stored. Data about the plugin is
|
||||||
* provided, and currently consists of:
|
* provided, and currently consists of:
|
||||||
* - loaded: true/false
|
* - loaded: true/false
|
||||||
* - implementation: gd/imagick/both
|
* - implementation: gd/imagick/both
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $_registry;
|
protected $_registry;
|
||||||
/**
|
/**
|
||||||
* What implementations are available
|
* What implementations are available
|
||||||
*
|
*
|
||||||
* This stores what implementations are available based on the loaded
|
* This stores what implementations are available based on the loaded
|
||||||
* extensions in PHP, NOT whether or not the class files are present.
|
* extensions in PHP, NOT whether or not the class files are present.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $_implementations;
|
protected $_implementations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of self
|
* Returns an instance of self
|
||||||
*
|
*
|
||||||
* This is the usual singleton function that returns / instantiates the object
|
* This is the usual singleton function that returns / instantiates the object
|
||||||
*
|
*
|
||||||
* @return PhpThumb
|
* @return PhpThumb
|
||||||
*/
|
*/
|
||||||
public static function getInstance ()
|
public static function getInstance ()
|
||||||
@ -87,29 +87,29 @@ class PhpThumb
|
|||||||
|
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* Initializes all the variables, and does some preliminary validation / checking of stuff
|
* Initializes all the variables, and does some preliminary validation / checking of stuff
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function __construct ()
|
private function __construct ()
|
||||||
{
|
{
|
||||||
$this->_registry = array();
|
$this->_registry = array();
|
||||||
$this->_implementations = array('gd' => false, 'imagick' => false);
|
$this->_implementations = array('gd' => false, 'imagick' => false);
|
||||||
|
|
||||||
$this->getImplementations();
|
$this->getImplementations();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds out what implementations are available
|
* Finds out what implementations are available
|
||||||
*
|
*
|
||||||
* This function loops over $this->_implementations and validates that the required extensions are loaded.
|
* This function loops over $this->_implementations and validates that the required extensions are loaded.
|
||||||
*
|
*
|
||||||
* I had planned on attempting to load them dynamically via dl(), but that would provide more overhead than I
|
* I had planned on attempting to load them dynamically via dl(), but that would provide more overhead than I
|
||||||
* was comfortable with (and would probably fail 99% of the time anyway)
|
* was comfortable with (and would probably fail 99% of the time anyway)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getImplementations ()
|
private function getImplementations ()
|
||||||
{
|
{
|
||||||
@ -119,22 +119,22 @@ class PhpThumb
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(extension_loaded($extension))
|
if(extension_loaded($extension))
|
||||||
{
|
{
|
||||||
$this->_implementations[$extension] = true;
|
$this->_implementations[$extension] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not $implementation is valid (available)
|
* Returns whether or not $implementation is valid (available)
|
||||||
*
|
*
|
||||||
* If 'all' is passed, true is only returned if ALL implementations are available.
|
* If 'all' is passed, true is only returned if ALL implementations are available.
|
||||||
*
|
*
|
||||||
* You can also pass 'n/a', which always returns true
|
* You can also pass 'n/a', which always returns true
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @param string $implementation
|
* @param string $implementation
|
||||||
*/
|
*/
|
||||||
public function isValidImplementation ($implementation)
|
public function isValidImplementation ($implementation)
|
||||||
@ -143,7 +143,7 @@ class PhpThumb
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($implementation == 'all')
|
if ($implementation == 'all')
|
||||||
{
|
{
|
||||||
foreach ($this->_implementations as $imp => $value)
|
foreach ($this->_implementations as $imp => $value)
|
||||||
@ -153,32 +153,32 @@ class PhpThumb
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($implementation, $this->_implementations))
|
if (array_key_exists($implementation, $this->_implementations))
|
||||||
{
|
{
|
||||||
return $this->_implementations[$implementation];
|
return $this->_implementations[$implementation];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a plugin in the registry
|
* Registers a plugin in the registry
|
||||||
*
|
*
|
||||||
* Adds a plugin to the registry if it isn't already loaded, and if the provided
|
* Adds a plugin to the registry if it isn't already loaded, and if the provided
|
||||||
* implementation is valid. Note that you can pass the following special keywords
|
* implementation is valid. Note that you can pass the following special keywords
|
||||||
* for implementation:
|
* for implementation:
|
||||||
* - all - Requires that all implementations be available
|
* - all - Requires that all implementations be available
|
||||||
* - n/a - Doesn't require any implementation
|
* - n/a - Doesn't require any implementation
|
||||||
*
|
*
|
||||||
* When a plugin is added to the registry, it's added as a key on $this->_registry with the value
|
* When a plugin is added to the registry, it's added as a key on $this->_registry with the value
|
||||||
* being an array containing the following keys:
|
* being an array containing the following keys:
|
||||||
* - loaded - whether or not the plugin has been "loaded" into the core class
|
* - loaded - whether or not the plugin has been "loaded" into the core class
|
||||||
* - implementation - what implementation this plugin is valid for
|
* - implementation - what implementation this plugin is valid for
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @param string $pluginName
|
* @param string $pluginName
|
||||||
* @param string $implementation
|
* @param string $implementation
|
||||||
@ -190,16 +190,16 @@ class PhpThumb
|
|||||||
$this->_registry[$pluginName] = array('loaded' => false, 'implementation' => $implementation);
|
$this->_registry[$pluginName] = array('loaded' => false, 'implementation' => $implementation);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all the plugins in $pluginPath
|
* Loads all the plugins in $pluginPath
|
||||||
*
|
*
|
||||||
* All this function does is include all files inside the $pluginPath directory. The plugins themselves
|
* All this function does is include all files inside the $pluginPath directory. The plugins themselves
|
||||||
* will not be added to the registry unless you've properly added the code to do so inside your plugin file.
|
* will not be added to the registry unless you've properly added the code to do so inside your plugin file.
|
||||||
*
|
*
|
||||||
* @param string $pluginPath
|
* @param string $pluginPath
|
||||||
*/
|
*/
|
||||||
public function loadPlugins ($pluginPath)
|
public function loadPlugins ($pluginPath)
|
||||||
@ -209,7 +209,7 @@ class PhpThumb
|
|||||||
{
|
{
|
||||||
$pluginPath = substr($pluginPath, 0, strlen($pluginPath) - 1);
|
$pluginPath = substr($pluginPath, 0, strlen($pluginPath) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($handle = opendir($pluginPath))
|
if ($handle = opendir($pluginPath))
|
||||||
{
|
{
|
||||||
while (false !== ($file = readdir($handle)))
|
while (false !== ($file = readdir($handle)))
|
||||||
@ -218,22 +218,22 @@ class PhpThumb
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once($pluginPath . '/' . $file);
|
include_once($pluginPath . '/' . $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the plugin registry for the supplied implementation
|
* Returns the plugin registry for the supplied implementation
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @param string $implementation
|
* @param string $implementation
|
||||||
*/
|
*/
|
||||||
public function getPluginRegistry ($implementation)
|
public function getPluginRegistry ($implementation)
|
||||||
{
|
{
|
||||||
$returnArray = array();
|
$returnArray = array();
|
||||||
|
|
||||||
foreach ($this->_registry as $plugin => $meta)
|
foreach ($this->_registry as $plugin => $meta)
|
||||||
{
|
{
|
||||||
if ($meta['implementation'] == 'n/a' || $meta['implementation'] == $implementation)
|
if ($meta['implementation'] == 'n/a' || $meta['implementation'] == $implementation)
|
||||||
@ -241,7 +241,7 @@ class PhpThumb
|
|||||||
$returnArray[$plugin] = $meta;
|
$returnArray[$plugin] = $meta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $returnArray;
|
return $returnArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ abstract class ThumbBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stristr($this->fileName, 'http://') !== false)
|
if (preg_match('/https?:\/\//', $this->fileName) !== 0)
|
||||||
{
|
{
|
||||||
$this->remoteImage = true;
|
$this->remoteImage = true;
|
||||||
return;
|
return;
|
||||||
@ -208,7 +208,7 @@ abstract class ThumbBase
|
|||||||
{
|
{
|
||||||
if( array_key_exists($method, $this->importedFunctions))
|
if( array_key_exists($method, $this->importedFunctions))
|
||||||
{
|
{
|
||||||
$args[] = $this;
|
$args[] =& $this;
|
||||||
return call_user_func_array(array($this->importedFunctions[$method], $method), $args);
|
return call_user_func_array(array($this->importedFunctions[$method], $method), $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PhpThumb Library Definition File
|
* PhpThumb Library Definition File
|
||||||
*
|
*
|
||||||
* This file contains the definitions for the PhpThumbFactory class.
|
* This file contains the definitions for the PhpThumbFactory class.
|
||||||
* It also includes the other required base class files.
|
* It also includes the other required base class files.
|
||||||
*
|
*
|
||||||
* If you've got some auto-loading magic going on elsewhere in your code, feel free to
|
* If you've got some auto-loading magic going on elsewhere in your code, feel free to
|
||||||
* remove the include_once statements at the beginning of this file... just make sure that
|
* remove the include_once statements at the beginning of this file... just make sure that
|
||||||
* these files get included one way or another in your code.
|
* these files get included one way or another in your code.
|
||||||
*
|
*
|
||||||
* PHP Version 5 with GD 2.0+
|
* PHP Version 5 with GD 2.0+
|
||||||
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
|
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
|
||||||
* Copyright (c) 2009, Ian Selby/Gen X Design
|
* Copyright (c) 2009, Ian Selby/Gen X Design
|
||||||
*
|
*
|
||||||
* Author(s): Ian Selby <ian@gen-x-design.com>
|
* Author(s): Ian Selby <ian@gen-x-design.com>
|
||||||
*
|
*
|
||||||
* Licensed under the MIT License
|
* Licensed under the MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Ian Selby <ian@gen-x-design.com>
|
* @author Ian Selby <ian@gen-x-design.com>
|
||||||
* @copyright Copyright (c) 2009 Gen X Design
|
* @copyright Copyright (c) 2009 Gen X Design
|
||||||
* @link http://phpthumb.gxdlabs.com
|
* @link http://phpthumb.gxdlabs.com
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
* @version 3.0
|
* @version 3.0
|
||||||
* @package PhpThumb
|
* @package PhpThumb
|
||||||
* @filesource $URL$
|
* @filesource
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// define some useful constants
|
// define some useful constants
|
||||||
@ -47,19 +47,19 @@ require_once THUMBLIB_BASE_PATH . '/GdThumb.inc.php';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PhpThumbFactory Object
|
* PhpThumbFactory Object
|
||||||
*
|
*
|
||||||
* This class is responsible for making sure everything is set up and initialized properly,
|
* This class is responsible for making sure everything is set up and initialized properly,
|
||||||
* and returning the appropriate thumbnail class instance. It is the only recommended way
|
* and returning the appropriate thumbnail class instance. It is the only recommended way
|
||||||
* of using this library, and if you try and circumvent it, the sky will fall on your head :)
|
* of using this library, and if you try and circumvent it, the sky will fall on your head :)
|
||||||
*
|
*
|
||||||
* Basic use is easy enough. First, make sure all the settings meet your needs and environment...
|
* Basic use is easy enough. First, make sure all the settings meet your needs and environment...
|
||||||
* these are the static variables defined at the beginning of the class.
|
* these are the static variables defined at the beginning of the class.
|
||||||
*
|
*
|
||||||
* Once that's all set, usage is pretty easy. You can simply do something like:
|
* Once that's all set, usage is pretty easy. You can simply do something like:
|
||||||
* <code>$thumb = PhpThumbFactory::create('/path/to/file.png');</code>
|
* <code>$thumb = PhpThumbFactory::create('/path/to/file.png');</code>
|
||||||
*
|
*
|
||||||
* Refer to the documentation for the create function for more information
|
* Refer to the documentation for the create function for more information
|
||||||
*
|
*
|
||||||
* @package PhpThumb
|
* @package PhpThumb
|
||||||
* @subpackage Core
|
* @subpackage Core
|
||||||
*/
|
*/
|
||||||
@ -67,30 +67,30 @@ class PhpThumbFactory
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Which implemenation of the class should be used by default
|
* Which implemenation of the class should be used by default
|
||||||
*
|
*
|
||||||
* Currently, valid options are:
|
* Currently, valid options are:
|
||||||
* - imagick
|
* - imagick
|
||||||
* - gd
|
* - gd
|
||||||
*
|
*
|
||||||
* These are defined in the implementation map variable, inside the create function
|
* These are defined in the implementation map variable, inside the create function
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public static $defaultImplemenation = DEFAULT_THUMBLIB_IMPLEMENTATION;
|
public static $defaultImplemenation = DEFAULT_THUMBLIB_IMPLEMENTATION;
|
||||||
/**
|
/**
|
||||||
* Where the plugins can be loaded from
|
* Where the plugins can be loaded from
|
||||||
*
|
*
|
||||||
* Note, it's important that this path is properly defined. It is very likely that you'll
|
* Note, it's important that this path is properly defined. It is very likely that you'll
|
||||||
* have to change this, as the assumption here is based on a relative path.
|
* have to change this, as the assumption here is based on a relative path.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public static $pluginPath = THUMBLIB_PLUGIN_PATH;
|
public static $pluginPath = THUMBLIB_PLUGIN_PATH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory Function
|
* Factory Function
|
||||||
*
|
*
|
||||||
* This function returns the correct thumbnail object, augmented with any appropriate plugins.
|
* This function returns the correct thumbnail object, augmented with any appropriate plugins.
|
||||||
* It does so by doing the following:
|
* It does so by doing the following:
|
||||||
* - Getting an instance of PhpThumb
|
* - Getting an instance of PhpThumb
|
||||||
* - Loading plugins
|
* - Loading plugins
|
||||||
@ -98,7 +98,7 @@ class PhpThumbFactory
|
|||||||
* - Returning the desired default implementation if possible
|
* - Returning the desired default implementation if possible
|
||||||
* - Returning the GD implemenation if the default isn't available
|
* - Returning the GD implemenation if the default isn't available
|
||||||
* - Throwing an exception if no required libraries are present
|
* - Throwing an exception if no required libraries are present
|
||||||
*
|
*
|
||||||
* @return GdThumb
|
* @return GdThumb
|
||||||
* @uses PhpThumb
|
* @uses PhpThumb
|
||||||
* @param string $filename The path and file to load [optional]
|
* @param string $filename The path and file to load [optional]
|
||||||
@ -111,15 +111,15 @@ class PhpThumbFactory
|
|||||||
'imagick' => 'ImagickThumb',
|
'imagick' => 'ImagickThumb',
|
||||||
'gd' => 'GdThumb'
|
'gd' => 'GdThumb'
|
||||||
);
|
);
|
||||||
|
|
||||||
// grab an instance of PhpThumb
|
// grab an instance of PhpThumb
|
||||||
$pt = PhpThumb::getInstance();
|
$pt = PhpThumb::getInstance();
|
||||||
// load the plugins
|
// load the plugins
|
||||||
$pt->loadPlugins(self::$pluginPath);
|
$pt->loadPlugins(self::$pluginPath);
|
||||||
|
|
||||||
$toReturn = null;
|
$toReturn = null;
|
||||||
$implementation = self::$defaultImplemenation;
|
$implementation = self::$defaultImplemenation;
|
||||||
|
|
||||||
// attempt to load the default implementation
|
// attempt to load the default implementation
|
||||||
if ($pt->isValidImplementation(self::$defaultImplemenation))
|
if ($pt->isValidImplementation(self::$defaultImplemenation))
|
||||||
{
|
{
|
||||||
@ -138,7 +138,7 @@ class PhpThumbFactory
|
|||||||
{
|
{
|
||||||
throw new Exception('You must have either the GD or iMagick extension loaded to use this library');
|
throw new Exception('You must have either the GD or iMagick extension loaded to use this library');
|
||||||
}
|
}
|
||||||
|
|
||||||
$registry = $pt->getPluginRegistry($implementation);
|
$registry = $pt->getPluginRegistry($implementation);
|
||||||
$toReturn->importPlugins($registry);
|
$toReturn->importPlugins($registry);
|
||||||
return $toReturn;
|
return $toReturn;
|
||||||
|
@ -46,12 +46,16 @@ class GdReflectionLib
|
|||||||
public function createReflection ($percent, $reflection, $white, $border, $borderColor, &$that)
|
public function createReflection ($percent, $reflection, $white, $border, $borderColor, &$that)
|
||||||
{
|
{
|
||||||
// bring stuff from the parent class into this class...
|
// bring stuff from the parent class into this class...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->parentInstance = $that;
|
$this->parentInstance = $that;
|
||||||
$this->currentDimensions = $this->parentInstance->getCurrentDimensions();
|
$this->currentDimensions = $this->parentInstance->getCurrentDimensions();
|
||||||
$this->workingImage = $this->parentInstance->getWorkingImage();
|
$this->workingImage = $this->parentInstance->getWorkingImage();
|
||||||
$this->newImage = $this->parentInstance->getOldImage();
|
$this->newImage = $this->parentInstance->getOldImage();
|
||||||
$this->options = $this->parentInstance->getOptions();
|
$this->options = $this->parentInstance->getOptions();
|
||||||
|
|
||||||
|
|
||||||
$width = $this->currentDimensions['width'];
|
$width = $this->currentDimensions['width'];
|
||||||
$height = $this->currentDimensions['height'];
|
$height = $this->currentDimensions['height'];
|
||||||
$reflectionHeight = intval($height * ($reflection / 100));
|
$reflectionHeight = intval($height * ($reflection / 100));
|
||||||
|
@ -30,15 +30,55 @@ class gallery_shortcodes extends e_shortcode
|
|||||||
|
|
||||||
function sc_gallery_thumb($parm='')
|
function sc_gallery_thumb($parm='')
|
||||||
{
|
{
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
$w = 190; $h = 150;
|
$w = 190;
|
||||||
|
$h = 150;
|
||||||
|
|
||||||
$class = ($this->slideMode == TRUE) ? 'gallery-slideshow-thumb' : 'gallery-thumb';
|
$class = ($this->slideMode == TRUE) ? 'gallery-slideshow-thumb' : 'gallery-thumb';
|
||||||
$rel = ($this->slideMode == TRUE) ? 'lightbox.SlideGallery' : 'lightbox.Gallery';
|
$rel = ($this->slideMode == TRUE) ? 'lightbox.SlideGallery' : 'lightbox.Gallery';
|
||||||
$att = ($parm) ?$parm : 'aw='.$w.'&ah='.$h ; // 'aw=190&ah=150';
|
$att = vartrue($parm) ? $parm : 'aw='.$w.'&ah='.$h ; // 'aw=190&ah=150';
|
||||||
$text = "<a class='".$class."' title='".$tp->toAttribute($this->var['media_caption'])."' href='".e107::getParser()->replaceConstants($this->var['media_url'],'abs')."' rel='{$rel}' >";
|
|
||||||
$text .= "<img class='".$class."' src='".e107::getParser()->thumbUrl($this->var['media_url'],$att)."' alt='' />";
|
$pop_w = vartrue(e107::getPlugPref('gallery','pop_w'),1024);
|
||||||
|
$pop_h = vartrue(e107::getPlugPref('gallery','pop_h'),768);
|
||||||
|
$attFull = 'w='.$pop_w.'&h='.$pop_h;
|
||||||
|
|
||||||
|
$wm_text = vartrue(e107::getPlugPref('gallery','watermark_text'));
|
||||||
|
$wm_font = vartrue(e107::getPlugPref('gallery','watermark_font'));
|
||||||
|
$wm_size = vartrue(e107::getPlugPref('gallery','watermark_size'),20);
|
||||||
|
$wm_pos = vartrue(e107::getPlugPref('gallery','watermark_pos'),"BR");
|
||||||
|
$wm_color = vartrue(e107::getPlugPref('gallery','watermark_color'),"fff");
|
||||||
|
$wm_opacity = vartrue(e107::getPlugPref('gallery','watermark_opacity'),"70");
|
||||||
|
$wm_padding = vartrue(e107::getPlugPref('gallery','watermark_padding'),"5");
|
||||||
|
|
||||||
|
/*
|
||||||
|
"wmt" (WaterMarkText)
|
||||||
|
[ex: &fltr[]=wmt|<t>|<s>|<a>|<c>|<f>|<o>|<m>|<n>]
|
||||||
|
where:
|
||||||
|
<t> is the text to use as a watermark,
|
||||||
|
<s> is the font size (1-5 for built-in font, or point
|
||||||
|
size for TrueType fonts),
|
||||||
|
<a> is the alignment (one of BR, BL, TR, TL, C, R, L,
|
||||||
|
T, B, * where B=bottom, T=top, L=left, R=right,
|
||||||
|
C=centre, *=tile),
|
||||||
|
<c> is the hex color of the text
|
||||||
|
<f> is the filename of the TTF file (optional, if
|
||||||
|
omitted a built-in font will be used)
|
||||||
|
<o> is opacity from 0 to 100,
|
||||||
|
<m> is the edge (and inter-tile) margin in percent
|
||||||
|
<n> is the angle
|
||||||
|
*/
|
||||||
|
|
||||||
|
if($wm_text)
|
||||||
|
{
|
||||||
|
$attFull .= "&wm=".$wm_text."|".$wm_size."|".$wm_pos."|".$wm_color."|".$wm_font."|".$wm_opacity."|".$wm_padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
// echo "<br /><br />".$attFull;
|
||||||
|
|
||||||
|
$text = "<a class='".$class."' title='".$tp->toAttribute($this->var['media_caption'])."' href='".$tp->thumbUrl($this->var['media_url'], $attFull)."' rel='{$rel}' >";
|
||||||
|
$text .= "<img class='".$class."' src='".$tp->thumbUrl($this->var['media_url'],$att)."' alt='' />";
|
||||||
$text .= "</a>";
|
$text .= "</a>";
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,16 @@ class gallery_cat_admin_ui extends e_admin_ui
|
|||||||
|
|
||||||
|
|
||||||
protected $prefs = array(
|
protected $prefs = array(
|
||||||
'slideshow_category' => array('title'=> 'Slideshow category', 'type' => 'dropdown', 'data' => 'integer', 'help'=>'Images from this category will be used in the sliding menu.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
'popup_w' => array('title'=> 'Image Max. Width', 'type' => 'text', 'data' => 'int', 'help'=>'Images will be auto-resized if greater than the width given here'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
'popup_h' => array('title'=> 'Image Max. Height', 'type' => 'text', 'data' => 'int', 'help'=>'Images will be auto-resized if greater than the height given here'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
|
||||||
|
'watermark_text' => array('title'=> 'Watermark Text', 'type' => 'text', 'data' => 'str', 'help'=>'Optional Watermark Text'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
'watermark_font' => array('title'=> 'Watermark Font', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Optional Watermark Font. Upload more .ttf fonts to the /fonts folder in your theme directory.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
'watermark_size' => array('title'=> 'Watermark Size', 'type' => 'text', 'data' => 'int', 'help'=>'Optional Watermark Font'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
'watermark_pos' => array('title'=> 'Watermark Position', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Watermark Position'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
'watermark_opacity' => array('title'=> 'Watermark Opacity', 'type' => 'text', 'data' => 'int', 'help'=>'Enter a number between 1 and 100'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
|
||||||
|
'slideshow_category' => array('title'=> 'Slideshow category', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Images from this category will be used in the sliding menu.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
// 'slideshow_thumb_w' => array('title'=> 'Thumbnail Width', 'type' => 'number', 'data' => 'integer', 'help'=>'Width in px'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
// 'slideshow_thumb_w' => array('title'=> 'Thumbnail Width', 'type' => 'number', 'data' => 'integer', 'help'=>'Width in px'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
// 'slideshow_thumb_h' => array('title'=> 'Thumbnail Height', 'type' => 'number', 'data' => 'integer', 'help'=>'Height in px'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
// 'slideshow_thumb_h' => array('title'=> 'Thumbnail Height', 'type' => 'number', 'data' => 'integer', 'help'=>'Height in px'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
|
||||||
|
|
||||||
@ -154,7 +163,39 @@ class gallery_cat_admin_ui extends e_admin_ui
|
|||||||
// 'zoom' => 'zoom'
|
// 'zoom' => 'zoom'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$pref = e107::getPref();
|
||||||
|
$tp = e107::getParser();
|
||||||
|
$fl = e107::getFile();
|
||||||
|
$path = e_THEME.$pref['sitetheme']."/fonts/";
|
||||||
|
|
||||||
|
$fDir = $fl->get_files(e_THEME.$pref['sitetheme']."/fonts/",".ttf",'',2);
|
||||||
|
$fonts = array(0=>'None');
|
||||||
|
foreach($fDir as $f)
|
||||||
|
{
|
||||||
|
$id = $tp->createConstants($f['path'].$f['fname'],'rel');
|
||||||
|
$fonts[$id] = $f['fname'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->prefs['watermark_font']['writeParms'] = $fonts;
|
||||||
|
$this->prefs['watermark_font']['readParms'] = $fonts;
|
||||||
|
|
||||||
|
$wm_pos = array(
|
||||||
|
'BR' => "Bottom Right",
|
||||||
|
'BL' => "Bottom Left",
|
||||||
|
'TR' => "Top Right",
|
||||||
|
'TL' => "Top Left",
|
||||||
|
'C' => "Center",
|
||||||
|
'R' => "Right",
|
||||||
|
'L' => "Left",
|
||||||
|
'T' => "Top",
|
||||||
|
'B' => "Bottom",
|
||||||
|
'*' => "Tile"
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->prefs['watermark_pos']['writeParms'] = $wm_pos;
|
||||||
|
$this->prefs['watermark_pos']['readParms'] = $wm_pos;
|
||||||
|
|
||||||
$this->prefs['slideshow_effect']['writeParms'] = $effects;
|
$this->prefs['slideshow_effect']['writeParms'] = $effects;
|
||||||
$this->prefs['slideshow_effect']['readParms'] = $effects;
|
$this->prefs['slideshow_effect']['readParms'] = $effects;
|
||||||
|
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
</siteLinks>
|
</siteLinks>
|
||||||
<mainPrefs>
|
<mainPrefs>
|
||||||
</mainPrefs>
|
</mainPrefs>
|
||||||
<pluginPrefs>
|
<pluginPrefs>
|
||||||
|
<pref name="popup_w">1024</pref>
|
||||||
|
<pref name="popup_h">768</pref>
|
||||||
<pref name="slideshow_category">1</pref>
|
<pref name="slideshow_category">1</pref>
|
||||||
<pref name="slideshow_duration">1</pref>
|
<pref name="slideshow_duration">1</pref>
|
||||||
<pref name="slideshow_auto">1</pref>
|
<pref name="slideshow_auto">1</pref>
|
||||||
|
@ -128,6 +128,7 @@ else
|
|||||||
if($pref['meta_copyright'][e_LANGUAGE]) e107::meta('copyright',$pref['meta_copyright'][e_LANGUAGE]);
|
if($pref['meta_copyright'][e_LANGUAGE]) e107::meta('copyright',$pref['meta_copyright'][e_LANGUAGE]);
|
||||||
if($pref['meta_author'][e_LANGUAGE]) e107::meta('author',$pref['meta_author'][e_LANGUAGE]);
|
if($pref['meta_author'][e_LANGUAGE]) e107::meta('author',$pref['meta_author'][e_LANGUAGE]);
|
||||||
if($pref['sitelogo']) e107::meta('og:image',$tp->replaceConstants($pref['sitelogo'],'full'));
|
if($pref['sitelogo']) e107::meta('og:image',$tp->replaceConstants($pref['sitelogo'],'full'));
|
||||||
|
if(defined("VIEWPORT")) e107::meta('viewport',VIEWPORT);
|
||||||
|
|
||||||
echo e107::getUrl()->response()->renderMeta()."\n";
|
echo e107::getUrl()->response()->renderMeta()."\n";
|
||||||
|
|
||||||
@ -436,6 +437,8 @@ function render_meta($type)
|
|||||||
|
|
||||||
echo (defined("META_DESCRIPTION")) ? "\n<meta name=\"description\" content=\"".$diz_merge.META_DESCRIPTION."\" />\n" : render_meta('description');
|
echo (defined("META_DESCRIPTION")) ? "\n<meta name=\"description\" content=\"".$diz_merge.META_DESCRIPTION."\" />\n" : render_meta('description');
|
||||||
echo (defined("META_KEYWORDS")) ? "\n<meta name=\"keywords\" content=\"".$key_merge.META_KEYWORDS."\" />\n" : render_meta('keywords');
|
echo (defined("META_KEYWORDS")) ? "\n<meta name=\"keywords\" content=\"".$key_merge.META_KEYWORDS."\" />\n" : render_meta('keywords');
|
||||||
|
|
||||||
|
|
||||||
//echo render_meta('copyright');
|
//echo render_meta('copyright');
|
||||||
//echo render_meta('author');
|
//echo render_meta('author');
|
||||||
echo render_meta('tag');
|
echo render_meta('tag');
|
||||||
|
22
thumb.php
22
thumb.php
@ -123,8 +123,10 @@ class e_thumbpage
|
|||||||
|
|
||||||
function parseRequest()
|
function parseRequest()
|
||||||
{
|
{
|
||||||
|
//echo 'e_query='.str_replace('&', '&', e_QUERY);
|
||||||
parse_str(str_replace('&', '&', e_QUERY), $this->_request);
|
parse_str(str_replace('&', '&', e_QUERY), $this->_request);
|
||||||
//parse_str($_SERVER['QUERY_STRING'], $this->_request);
|
|
||||||
|
// parse_str($_SERVER['QUERY_STRING'], $this->_request);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,6 +230,23 @@ class e_thumbpage
|
|||||||
$thumb->adaptiveResize((integer) vartrue($this->_request['aw'], 0), (integer) vartrue($this->_request['ah'], 0));
|
$thumb->adaptiveResize((integer) vartrue($this->_request['aw'], 0), (integer) vartrue($this->_request['ah'], 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO Move to $_SESSION and activate based on width/height ie. watermark all images larger than....
|
||||||
|
// ie. prevent user tampering with URLs.
|
||||||
|
if(isset($this->_request['wm']))
|
||||||
|
{
|
||||||
|
$tp = e107::getParser();
|
||||||
|
|
||||||
|
$tmp = explode("|",$this->_request['wm']);
|
||||||
|
|
||||||
|
$tmp[4] = $tp->createConstants($tmp[4], 'mix');
|
||||||
|
$tmp[4] = realpath($tp->replaceConstants($tmp[4],'rel'));
|
||||||
|
|
||||||
|
$thumb->WatermarkText($tmp);
|
||||||
|
// $alignment='BR', $hex_color='000000', $ttffont='', $opacity=100, $margin=5, $angle=0, $bg_color=false, $bg_opacity=0, $fillextend=''
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// set cache
|
// set cache
|
||||||
$thumb->save(e_CACHE_IMAGE.$fname);
|
$thumb->save(e_CACHE_IMAGE.$fname);
|
||||||
|
|
||||||
@ -242,6 +261,7 @@ class e_thumbpage
|
|||||||
$ret['h'] = isset($this->_request['h']) ? intval($this->_request['h']) : $ret['w'];
|
$ret['h'] = isset($this->_request['h']) ? intval($this->_request['h']) : $ret['w'];
|
||||||
$ret['aw'] = isset($this->_request['aw']) ? intval($this->_request['aw']) : false;
|
$ret['aw'] = isset($this->_request['aw']) ? intval($this->_request['aw']) : false;
|
||||||
$ret['ah'] = isset($this->_request['ah']) ? intval($this->_request['ah']) : $ret['aw'];
|
$ret['ah'] = isset($this->_request['ah']) ? intval($this->_request['ah']) : $ret['aw'];
|
||||||
|
$ret['wm'] = isset($this->_request['wm']) ? intval($this->_request['wm']) : $ret['wm'];
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user