1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-06 08:07:42 +02:00

updating phpdoc

This commit is contained in:
Mikael Roos
2015-03-06 12:38:36 +01:00
parent 8a7a056694
commit 169b99eab3
19 changed files with 775 additions and 764 deletions

View File

@@ -135,9 +135,9 @@ class CImage
/**
* Original file extension
* File type for source image, as provided by getimagesize()
*/
private $fileExtension;
private $fileType;
@@ -513,6 +513,10 @@ class CImage
*/
public function downloadRemoteSource($src)
{
if (!$this->isRemoteSourceOnWhitelist($src)) {
throw new Exception("Hostname is not on whitelist for remote sources.");
}
$remote = new CRemoteImage();
$cache = $this->saveFolder . "/remote/";
@@ -568,10 +572,6 @@ class CImage
$this->imageSrc = ltrim($src, '/');
$this->imageFolder = rtrim($dir, '/');
$this->pathToImage = $this->imageFolder . '/' . $this->imageSrc;
$this->fileExtension = strtolower(pathinfo($this->pathToImage, PATHINFO_EXTENSION));
//$this->extension = $this->fileExtension;
$this->checkFileExtension($this->fileExtension);
return $this;
}
@@ -776,13 +776,14 @@ class CImage
or $this->raiseError('Image file does not exist.');
// Get details on image
$info = list($this->width, $this->height, $this->type, $this->attr) = getimagesize($file);
$info = list($this->width, $this->height, $this->fileType, $this->attr) = getimagesize($file);
!empty($info) or $this->raiseError("The file doesn't seem to be an image.");
if ($this->verbose) {
$this->log("Image file: {$file}");
$this->log("Image width x height (type): {$this->width} x {$this->height} ({$this->type}).");
$this->log("Image filesize: " . filesize($file) . " bytes.");
$this->log("Loading image details for: {$file}");
$this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType}).");
$this->log(" Image filesize: " . filesize($file) . " bytes.");
$this->log(" Image mimetype: " . image_type_to_mime_type($this->fileType));
}
return $this;
@@ -1047,7 +1048,7 @@ class CImage
$this->extension = $saveAs;
}
$this->log("Prepare to save image using as: " . $this->extension);
$this->log("Prepare to save image as: " . $this->extension);
return $this;
}
@@ -1201,15 +1202,17 @@ class CImage
$this->extension = isset($this->extension)
? $this->extension
: $parts['extension'];
: (isset($parts['extension'])
? $parts['extension']
: null);
$extension = empty($this->extension)
? null
: "." . $this->extension;
$optimize = null;
if ($this->extension == 'jpeg' || $this->extension == 'jpg') {
$optimize = $this->jpegOptimize ? 'o' : null;
} elseif ($this->extension == 'png') {
$optimize .= $this->pngFilter ? 'f' : null;
$optimize .= $this->pngDeflate ? 'd' : null;
}
$optimize = $this->jpegOptimize ? 'o' : null;
$optimize .= $this->pngFilter ? 'f' : null;
$optimize .= $this->pngDeflate ? 'd' : null;
$convolve = null;
if ($this->convolve) {
@@ -1228,7 +1231,7 @@ class CImage
. $crop_x . $crop_y . $upscale
. $quality . $filters . $sharpen . $emboss . $blur . $palette . $optimize
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor . $convolve
. '.' . $this->extension;
. $extension;
return $this->setTarget($file, $base);
}
@@ -1271,7 +1274,7 @@ class CImage
/**
* Error message when failing to load somehow corrupt image.
* To display error message when failing to load somehow corrupt image.
*
* @return void
*
@@ -1280,29 +1283,15 @@ class CImage
{
header("HTTP/1.0 404 Not Found");
echo("CImage.php says 404: Fatal error when opening image.<br>");
switch ($this->fileExtension) {
case 'jpg':
case 'jpeg':
$this->image = imagecreatefromjpeg($this->pathToImage);
break;
case 'gif':
$this->image = imagecreatefromgif($this->pathToImage);
break;
case 'png':
$this->image = imagecreatefrompng($this->pathToImage);
break;
}
$image = imagecreatefromstring(file_get_contents($this->pathToImage));
exit();
}
/**
* Load image from disk.
* Load image from disk. Try to load image without verbose error message,
* if fail, load again and display error messages.
*
* @param string $src of image.
* @param string $dir as base directory where images are.
@@ -1316,46 +1305,30 @@ class CImage
$this->setSource($src, $dir);
}
$this->log("Opening file as {$this->fileExtension}.");
$this->loadImageDetails($this->pathToImage);
switch ($this->fileExtension) {
case 'jpg':
case 'jpeg':
$this->image = @imagecreatefromjpeg($this->pathToImage);
$this->image or $this->failedToLoad();
break;
$this->image = @imagecreatefromstring(file_get_contents($this->pathToImage));
$this->image or $this->failedToLoad();
if (image_type_to_mime_type($this->fileType) == 'image/png') {
$type = $this->getPngType();
$hasFewColors = imagecolorstotal($this->image);
case 'gif':
$this->image = @imagecreatefromgif($this->pathToImage);
$this->image or $this->failedToLoad();
break;
case 'png':
$this->image = @imagecreatefrompng($this->pathToImage);
$this->image or $this->failedToLoad();
$type = $this->getPngType();
$hasFewColors = imagecolorstotal($this->image);
if ($type == self::PNG_RGB_PALETTE || ($hasFewColors > 0 && $hasFewColors <= 256)) {
if ($this->verbose) {
$this->log("Handle this image as a palette image.");
}
$this->palette = true;
if ($type == self::PNG_RGB_PALETTE || ($hasFewColors > 0 && $hasFewColors <= 256)) {
if ($this->verbose) {
$this->log("Handle this image as a palette image.");
}
break;
default:
$this->image = false;
throw new Exception('No support for this file extension.');
$this->palette = true;
}
}
if ($this->verbose) {
$this->log("imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false'));
$this->log("imagecolorstotal() : " . imagecolorstotal($this->image));
$this->log("Number of colors in image = " . $this->colorsTotal($this->image));
$this->log("Image successfully loaded from file.");
$this->log(" imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false'));
$this->log(" imagecolorstotal() : " . imagecolorstotal($this->image));
$this->log(" Number of colors in image = " . $this->colorsTotal($this->image));
$index = imagecolortransparent($this->image);
$this->log("Detected transparent color = " . ($index > 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index");
$this->log(" Detected transparent color = " . ($index > 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index");
}
return $this;
@@ -1750,7 +1723,7 @@ class CImage
*/
public function rotateExif()
{
if (!in_array($this->fileExtension, array('jpg', 'jpeg'))) {
if (!in_array($this->fileType, array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) {
$this->log("Autorotate ignored, EXIF not supported by this filetype.");
return $this;
}
@@ -2094,6 +2067,22 @@ class CImage
/**
* Find out the type (file extension) for the image to be saved.
*
* @return string as image extension.
*/
protected function getTargetImageExtension()
{
if (isset($this->extension)) {
return strtolower($this->extension);
} else {
return image_type_to_extension($this->fileType);
}
}
/**
* Save image.
*
@@ -2111,7 +2100,7 @@ class CImage
is_writable($this->saveFolder)
or $this->raiseError('Target directory is not writable.');
switch(strtolower($this->extension)) {
switch($this->getTargetImageExtension()) {
case 'jpeg':
case 'jpg':
@@ -2138,6 +2127,7 @@ class CImage
break;
case 'png':
default:
$this->Log("Saving image as PNG to cache using compression = {$this->compress}.");
// Turn off alpha blending and set alpha flag
@@ -2171,20 +2161,17 @@ class CImage
$this->Log($res);
}
break;
default:
$this->RaiseError('No support for this file extension.');
break;
}
if ($this->verbose) {
clearstatcache();
$this->log("Cached image filesize: " . filesize($this->cacheFileName) . " bytes.");
$this->log("imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false'));
$this->log("imagecolorstotal() : " . imagecolorstotal($this->image));
$this->log("Number of colors in image = " . $this->ColorsTotal($this->image));
$this->log("Saved image to cache.");
$this->log(" Cached image filesize: " . filesize($this->cacheFileName) . " bytes.");
$this->log(" imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false'));
$this->log(" imagecolorstotal() : " . imagecolorstotal($this->image));
$this->log(" Number of colors in image = " . $this->ColorsTotal($this->image));
$index = imagecolortransparent($this->image);
$this->log("Detected transparent color = " . ($index > 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index");
$this->log(" Detected transparent color = " . ($index > 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index");
}
return $this;
@@ -2207,7 +2194,7 @@ class CImage
return $this;
}
$alias = $alias . "." . $this->extension;
$alias = $alias . "." . $this->getTargetImageExtension();
if (is_readable($alias)) {
unlink($alias);
@@ -2310,23 +2297,22 @@ class CImage
clearstatcache();
$details['src'] = $this->imageSrc;
$lastModified = filemtime($this->pathToImage);
$details['src'] = $this->imageSrc;
$lastModified = filemtime($this->pathToImage);
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
$details['cache'] = basename($this->cacheFileName);
$lastModified = filemtime($this->cacheFileName);
$details['cache'] = basename($this->cacheFileName);
$lastModified = filemtime($this->cacheFileName);
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
$this->loadImageDetails($file);
$details['filename'] = basename($file);
$details['width'] = $this->width;
$details['height'] = $this->height;
$details['aspectRatio'] = round($this->width / $this->height, 3);
$details['size'] = filesize($file);
$this->load($file);
$details['filename'] = basename($file);
$details['mimeType'] = image_type_to_mime_type($this->fileType);
$details['width'] = $this->width;
$details['height'] = $this->height;
$details['aspectRatio'] = round($this->width / $this->height, 3);
$details['size'] = filesize($file);
$details['colors'] = $this->colorsTotal($this->image);
$options = null;