-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
+
-
-
-
+
+
diff --git a/core/vendor/filemanager/execute.php b/core/vendor/filemanager/execute.php
index 0321bfaf..2fa76832 100644
--- a/core/vendor/filemanager/execute.php
+++ b/core/vendor/filemanager/execute.php
@@ -41,7 +41,21 @@ while ($cycle && $i < $max_cycles) {
}
if (file_exists($path . "config.php")) {
- require_once $path . "config.php";
+ $configMain = $config;
+ $configTemp = include $path . "config.php";
+ if(is_array($configTemp) && count($configTemp) > 0){
+ $config = array_merge($configMain, $configTemp);
+ $config['ext'] = array_merge(
+ $config['ext_img'],
+ $config['ext_file'],
+ $config['ext_misc'],
+ $config['ext_video'],
+ $config['ext_music']
+ );
+ }
+ else{
+ $config = $configMain;
+ }
$cycle = false;
}
$path = fix_dirname($path) . "/";
diff --git a/core/vendor/filemanager/include/Response.php b/core/vendor/filemanager/include/Response.php
index ae9f10c9..970299ab 100644
--- a/core/vendor/filemanager/include/Response.php
+++ b/core/vendor/filemanager/include/Response.php
@@ -1,4 +1,4 @@
- 'Continue',
- 101 => 'Switching Protocols',
- 102 => 'Processing', // RFC2518
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
- 207 => 'Multi-Status', // RFC4918
- 208 => 'Already Reported', // RFC5842
- 226 => 'IM Used', // RFC3229
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found',
- 303 => 'See Other',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 306 => 'Reserved',
- 307 => 'Temporary Redirect',
- 308 => 'Permanent Redirect', // RFC7238
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 402 => 'Payment Required',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed',
- 418 => 'I\'m a teapot', // RFC2324
- 422 => 'Unprocessable Entity', // RFC4918
- 423 => 'Locked', // RFC4918
- 424 => 'Failed Dependency', // RFC4918
- 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
- 426 => 'Upgrade Required', // RFC2817
- 428 => 'Precondition Required', // RFC6585
- 429 => 'Too Many Requests', // RFC6585
- 431 => 'Request Header Fields Too Large', // RFC6585
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported',
- 506 => 'Variant Also Negotiates (Experimental)', // RFC2295
- 507 => 'Insufficient Storage', // RFC4918
- 508 => 'Loop Detected', // RFC5842
- 510 => 'Not Extended', // RFC2774
- 511 => 'Network Authentication Required', // RFC6585
- );
+ /**
+ * Status codes translation table.
+ *
+ * The list of codes is complete according to the
+ * {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry}
+ * (last updated 2012-02-13).
+ *
+ * Unless otherwise noted, the status code is defined in RFC2616.
+ *
+ * @var array
+ */
+ public static $statusTexts = array(
+ 100 => 'Continue',
+ 101 => 'Switching Protocols',
+ 102 => 'Processing', // RFC2518
+ 200 => 'OK',
+ 201 => 'Created',
+ 202 => 'Accepted',
+ 203 => 'Non-Authoritative Information',
+ 204 => 'No Content',
+ 205 => 'Reset Content',
+ 206 => 'Partial Content',
+ 207 => 'Multi-Status', // RFC4918
+ 208 => 'Already Reported', // RFC5842
+ 226 => 'IM Used', // RFC3229
+ 300 => 'Multiple Choices',
+ 301 => 'Moved Permanently',
+ 302 => 'Found',
+ 303 => 'See Other',
+ 304 => 'Not Modified',
+ 305 => 'Use Proxy',
+ 306 => 'Reserved',
+ 307 => 'Temporary Redirect',
+ 308 => 'Permanent Redirect', // RFC7238
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 402 => 'Payment Required',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ 406 => 'Not Acceptable',
+ 407 => 'Proxy Authentication Required',
+ 408 => 'Request Timeout',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 411 => 'Length Required',
+ 412 => 'Precondition Failed',
+ 413 => 'Request Entity Too Large',
+ 414 => 'Request-URI Too Long',
+ 415 => 'Unsupported Media Type',
+ 416 => 'Requested Range Not Satisfiable',
+ 417 => 'Expectation Failed',
+ 418 => 'I\'m a teapot', // RFC2324
+ 422 => 'Unprocessable Entity', // RFC4918
+ 423 => 'Locked', // RFC4918
+ 424 => 'Failed Dependency', // RFC4918
+ 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
+ 426 => 'Upgrade Required', // RFC2817
+ 428 => 'Precondition Required', // RFC6585
+ 429 => 'Too Many Requests', // RFC6585
+ 431 => 'Request Header Fields Too Large', // RFC6585
+ 500 => 'Internal Server Error',
+ 501 => 'Not Implemented',
+ 502 => 'Bad Gateway',
+ 503 => 'Service Unavailable',
+ 504 => 'Gateway Timeout',
+ 505 => 'HTTP Version Not Supported',
+ 506 => 'Variant Also Negotiates (Experimental)', // RFC2295
+ 507 => 'Insufficient Storage', // RFC4918
+ 508 => 'Loop Detected', // RFC5842
+ 510 => 'Not Extended', // RFC2774
+ 511 => 'Network Authentication Required', // RFC6585
+ );
- /**
- * @var string
- */
- protected $content;
+ /**
+ * @var string
+ */
+ protected $content;
- /**
- * @var int
- */
- protected $statusCode;
+ /**
+ * @var int
+ */
+ protected $statusCode;
- /**
- * @var string
- */
- protected $statusText;
+ /**
+ * @var string
+ */
+ protected $statusText;
- /**
- * @var array
- */
- public $headers;
+ /**
+ * @var array
+ */
+ public $headers;
- /**
- * @var string
- */
- protected $version;
+ /**
+ * @var string
+ */
+ protected $version;
- /**
- * Construct the response
- *
- * @param mixed $content
- * @param int $statusCode
- * @param array $headers
- */
- public function __construct($content = '', $statusCode = 200, $headers = array())
- {
- $this->setContent($content);
- $this->setStatusCode($statusCode);
- $this->headers = $headers;
- $this->version = '1.1';
- }
+ /**
+ * Construct the response
+ *
+ * @param mixed $content
+ * @param int $statusCode
+ * @param array $headers
+ */
+ public function __construct($content = '', $statusCode = 200, $headers = array())
+ {
+ $this->setContent($content);
+ $this->setStatusCode($statusCode);
+ $this->headers = $headers;
+ $this->version = '1.1';
+ }
- /**
- * Set the content on the response.
- *
- * @param mixed $content
- * @return $this
- */
- public function setContent($content)
- {
- if ($content instanceof ArrayObject || is_array($content))
- {
- $this->headers['Content-Type'] = array('application/json');
+ /**
+ * Set the content on the response.
+ *
+ * @param mixed $content
+ * @return $this
+ */
+ public function setContent($content)
+ {
+ if ($content instanceof ArrayObject || is_array($content))
+ {
+ $this->headers['Content-Type'] = array('application/json');
- $content = json_encode($content);
- }
+ $content = json_encode($content);
+ }
- $this->content = $content;
- }
+ $this->content = $content;
+ }
- /**
- * Returns the Response as an HTTP string.
- *
- * The string representation of the Response is the same as the
- * one that will be sent to the client only if the prepare() method
- * has been called before.
- *
- * @return string The Response as an HTTP string
- *
- * @see prepare()
- */
- public function __toString()
- {
- return
- sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
- $this->headers."\r\n".
- $this->getContent();
- }
+ /**
+ * Returns the Response as an HTTP string.
+ *
+ * The string representation of the Response is the same as the
+ * one that will be sent to the client only if the prepare() method
+ * has been called before.
+ *
+ * @return string The Response as an HTTP string
+ *
+ * @see prepare()
+ */
+ public function __toString()
+ {
+ return
+ sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
+ $this->headers."\r\n".
+ $this->getContent();
+ }
- /**
- * Sets the response status code.
- *
- * @param int $code HTTP status code
- * @param mixed $text HTTP status text
- *
- * If the status text is null it will be automatically populated for the known
- * status codes and left empty otherwise.
- *
- * @return Response
- *
- * @throws \InvalidArgumentException When the HTTP status code is not valid
- *
- * @api
- */
- public function setStatusCode($code, $text = null)
- {
- $this->statusCode = $code = (int) $code;
- if ($this->isInvalid()) {
- throw new InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
- }
+ /**
+ * Sets the response status code.
+ *
+ * @param int $code HTTP status code
+ * @param mixed $text HTTP status text
+ *
+ * If the status text is null it will be automatically populated for the known
+ * status codes and left empty otherwise.
+ *
+ * @return Response
+ *
+ * @throws \InvalidArgumentException When the HTTP status code is not valid
+ *
+ * @api
+ */
+ public function setStatusCode($code, $text = null)
+ {
+ $this->statusCode = $code = (int) $code;
+ if ($this->isInvalid()) {
+ throw new InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
+ }
- if (null === $text) {
- $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : '';
+ if (null === $text) {
+ $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : '';
- return $this;
- }
+ return $this;
+ }
- if (false === $text) {
- $this->statusText = '';
+ if (false === $text) {
+ $this->statusText = '';
- return $this;
- }
+ return $this;
+ }
- $this->statusText = $text;
+ $this->statusText = $text;
- return $this;
- }
+ return $this;
+ }
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
- /**
- * Is response invalid?
- *
- * @return bool
- *
- * @api
- */
- public function isInvalid()
- {
- return $this->statusCode < 100 || $this->statusCode >= 600;
- }
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
+ /**
+ * Is response invalid?
+ *
+ * @return bool
+ *
+ * @api
+ */
+ public function isInvalid()
+ {
+ return $this->statusCode < 100 || $this->statusCode >= 600;
+ }
- /**
- * Set a header on the Response.
- *
- * @param string $key
- * @param string $value
- * @param bool $replace
- * @return $this
- */
- public function header($key, $value, $replace = true)
- {
- if (empty($this->headers[$key]))
- {
- $this->headers[$key] = array();
- }
- if ($replace)
- {
- $this->headers[$key] = array($value);
- }
- else
- {
- $this->headers[$key][] = $value;
- }
+ /**
+ * Set a header on the Response.
+ *
+ * @param string $key
+ * @param string $value
+ * @param bool $replace
+ * @return $this
+ */
+ public function header($key, $value, $replace = true)
+ {
+ if (empty($this->headers[$key]))
+ {
+ $this->headers[$key] = array();
+ }
+ if ($replace)
+ {
+ $this->headers[$key] = array($value);
+ }
+ else
+ {
+ $this->headers[$key][] = $value;
+ }
- return $this;
- }
+ return $this;
+ }
- /**
- * Sends HTTP headers and content.
- *
- * @return Response
- *
- * @api
- */
- public function send()
- {
- $this->sendHeaders();
- $this->sendContent();
+ /**
+ * Sends HTTP headers and content.
+ *
+ * @return Response
+ *
+ * @api
+ */
+ public function send()
+ {
+ $this->sendHeaders();
+ $this->sendContent();
- if (function_exists('fastcgi_finish_request')) {
- fastcgi_finish_request();
- }
+ if (function_exists('fastcgi_finish_request')) {
+ fastcgi_finish_request();
+ }
- return $this;
- }
+ return $this;
+ }
- /**
- * Sends content for the current web response.
- *
- * @return Response
- */
- public function sendContent()
- {
- echo $this->content;
+ /**
+ * Sends content for the current web response.
+ *
+ * @return Response
+ */
+ public function sendContent()
+ {
+ echo $this->content;
- return $this;
- }
+ return $this;
+ }
- /**
- * Sends HTTP headers.
- *
- * @return Response
- */
- public function sendHeaders()
- {
- // headers have already been sent by the developer
- if (headers_sent()) {
- return $this;
- }
+ /**
+ * Sends HTTP headers.
+ *
+ * @return Response
+ */
+ public function sendHeaders()
+ {
+ // headers have already been sent by the developer
+ if (headers_sent()) {
+ return $this;
+ }
- // status
- header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
+ // status
+ header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
- // headers
- foreach ($this->headers as $name => $values) {
- if (is_array($values))
- {
- foreach ($values as $value)
- {
- header($name . ': ' . $value, false, $this->statusCode);
- }
- }
- else
- {
- header($name . ': ' . $values, false, $this->statusCode);
- }
- }
+ // headers
+ foreach ($this->headers as $name => $values) {
+ if (is_array($values))
+ {
+ foreach ($values as $value)
+ {
+ header($name . ': ' . $value, false, $this->statusCode);
+ }
+ }
+ else
+ {
+ header($name . ': ' . $values, false, $this->statusCode);
+ }
+ }
- return $this;
- }
+ return $this;
+ }
}
\ No newline at end of file
diff --git a/core/vendor/filemanager/include/get_png_imageinfo.php b/core/vendor/filemanager/include/get_png_imageinfo.php
new file mode 100644
index 00000000..17e8dd03
--- /dev/null
+++ b/core/vendor/filemanager/include/get_png_imageinfo.php
@@ -0,0 +1,75 @@
+
+ * @license Apache 2.0
+ * @link https://github.com/ktomk/Miscellaneous/blob/master/get_png_imageinfo/get_png_imageinfo.php
+ * @link http://www.libpng.org/pub/png/spec/iso/index-object.html#11IHDR
+ *
+ * @param string $file filename
+ * @return array|bool image information, FALSE on error
+ */
+function get_png_imageinfo($file) {
+ if (! is_file($file)) {
+ return false;
+ }
+
+ $info = unpack(
+ 'a8sig/Nchunksize/A4chunktype/Nwidth/Nheight/Cbit-depth/Ccolor/Ccompression/Cfilter/Cinterface',
+ file_get_contents($file, 0, null, 0, 29)
+ );
+
+ if (empty($info)) {
+ return false;
+ }
+ if ("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" != array_shift($info)) {
+ return false; // no PNG signature
+ }
+ if (13 != array_shift($info)) {
+ return false; // wrong length for IHDR chunk
+ }
+ if ('IHDR'!==array_shift($info)) {
+ return false; // a non-IHDR chunk singals invalid data
+ }
+
+ $color = $info['color'];
+ $type = array(
+ 0 => 'Greyscale',
+ 2 => 'Truecolour',
+ 3 => 'Indexed-colour',
+ 4 => 'Greyscale with alpha',
+ 6 => 'Truecolour with alpha'
+ );
+
+ if (empty($type[$color])) {
+ return false; // invalid color value
+ }
+
+ $info['color-type'] = $type[$color];
+ $samples = ((($color % 4) % 3) ? 3 : 1) + ($color > 3 ? 1 : 0);
+ $info['channels'] = $samples;
+ $info['bits'] = $info['bit-depth'];
+
+ return $info;
+}
diff --git a/core/vendor/filemanager/include/mime_type_lib.php b/core/vendor/filemanager/include/mime_type_lib.php
index 861470ca..e20a0701 100644
--- a/core/vendor/filemanager/include/mime_type_lib.php
+++ b/core/vendor/filemanager/include/mime_type_lib.php
@@ -1,249 +1,252 @@
"ps",
- "audio/x-aiff" => "aiff",
- "text/plain" => "txt",
- "video/x-ms-asf" => "asx",
- "audio/basic" => "snd",
- "video/x-msvideo" => "avi",
- "application/x-bcpio" => "bcpio",
- "application/octet-stream" => "so",
- "image/bmp" => "bmp",
- "application/x-rar" => "rar",
- "application/x-bzip2" => "bz2",
- "application/x-netcdf" => "nc",
- "application/x-kchart" => "chrt",
- "application/x-cpio" => "cpio",
- "application/mac-compactpro" => "cpt",
- "application/x-csh" => "csh",
- "text/css" => "css",
- "application/x-director" => "dxr",
- "image/vnd.djvu" => "djvu",
- "application/x-dvi" => "dvi",
- "image/vnd.dwg" => "dwg",
- "application/epub" => "epub",
- "application/epub+zip" => "epub",
- "text/x-setext" => "etx",
- "application/andrew-inset" => "ez",
- "video/x-flv" => "flv",
- "image/gif" => "gif",
- "application/x-gtar" => "gtar",
- "application/x-gzip" => "tgz",
- "application/x-hdf" => "hdf",
- "application/mac-binhex40" => "hqx",
- "text/html" => "html",
- "text/htm" => "htm",
- "x-conference/x-cooltalk" => "ice",
- "image/ief" => "ief",
- "model/iges" => "igs",
- "text/vnd.sun.j2me.app-descriptor" => "jad",
- "application/x-java-archive" => "jar",
- "application/x-java-jnlp-file" => "jnlp",
- "image/jpeg" => "jpg",
- "application/x-javascript" => "js",
- "audio/midi" => "midi",
- "application/x-killustrator" => "kil",
- "application/x-kpresenter" => "kpt",
- "application/x-kspread" => "ksp",
- "application/x-kword" => "kwt",
- "application/vnd.google-earth.kml+xml" => "kml",
- "application/vnd.google-earth.kmz" => "kmz",
- "application/x-latex" => "latex",
- "audio/x-mpegurl" => "m3u",
- "application/x-troff-man" => "man",
- "application/x-troff-me" => "me",
- "model/mesh" => "silo",
- "application/vnd.mif" => "mif",
- "video/quicktime" => "mov",
- "video/x-sgi-movie" => "movie",
- "audio/mpeg" => "mp3",
- "video/mp4" => "mp4",
- "video/mpeg" => "mpeg",
- "application/x-troff-ms" => "ms",
- "video/vnd.mpegurl" => "mxu",
- "application/vnd.oasis.opendocument.database" => "odb",
- "application/vnd.oasis.opendocument.chart" => "odc",
- "application/vnd.oasis.opendocument.formula" => "odf",
- "application/vnd.oasis.opendocument.graphics" => "odg",
- "application/vnd.oasis.opendocument.image" => "odi",
- "application/vnd.oasis.opendocument.text-master" => "odm",
- "application/vnd.oasis.opendocument.presentation" => "odp",
- "application/vnd.oasis.opendocument.spreadsheet" => "ods",
- "application/vnd.oasis.opendocument.text" => "odt",
- "application/ogg" => "ogg",
- "video/ogg" => "ogv",
- "application/vnd.oasis.opendocument.graphics-template" => "otg",
- "application/vnd.oasis.opendocument.text-web" => "oth",
- "application/vnd.oasis.opendocument.presentation-template" => "otp",
- "application/vnd.oasis.opendocument.spreadsheet-template" => "ots",
- "application/vnd.oasis.opendocument.text-template" => "ott",
- "image/x-portable-bitmap" => "pbm",
- "chemical/x-pdb" => "pdb",
- "application/pdf" => "pdf",
- "image/x-portable-graymap" => "pgm",
- "application/x-chess-pgn" => "pgn",
- "text/x-php" => "php",
- "image/png" => "png",
- "image/x-portable-anymap" => "pnm",
- "image/x-portable-pixmap" => "ppm",
- "application/vnd.ms-powerpoint" => "ppt",
- "audio/x-realaudio" => "ra",
- "audio/x-pn-realaudio" => "rm",
- "image/x-cmu-raster" => "ras",
- "image/x-rgb" => "rgb",
- "application/x-troff" => "tr",
- "application/x-rpm" => "rpm",
- "text/rtf" => "rtf",
- "text/richtext" => "rtx",
- "text/sgml" => "sgml",
- "application/x-sh" => "sh",
- "application/x-shar" => "shar",
- "application/vnd.symbian.install" => "sis",
- "application/x-stuffit" => "sit",
- "application/x-koan" => "skt",
- "application/smil" => "smil",
- "image/svg+xml" => "svg",
- "application/x-futuresplash" => "spl",
- "application/x-wais-source" => "src",
- "application/vnd.sun.xml.calc.template" => "stc",
- "application/vnd.sun.xml.draw.template" => "std",
- "application/vnd.sun.xml.impress.template" => "sti",
- "application/vnd.sun.xml.writer.template" => "stw",
- "application/x-sv4cpio" => "sv4cpio",
- "application/x-sv4crc" => "sv4crc",
- "application/x-shockwave-flash" => "swf",
- "application/vnd.sun.xml.calc" => "sxc",
- "application/vnd.sun.xml.draw" => "sxd",
- "application/vnd.sun.xml.writer.global" => "sxg",
- "application/vnd.sun.xml.impress" => "sxi",
- "application/vnd.sun.xml.math" => "sxm",
- "application/vnd.sun.xml.writer" => "sxw",
- "application/x-tar" => "tar",
- "application/x-tcl" => "tcl",
- "application/x-tex" => "tex",
- "application/x-texinfo" => "texinfo",
- "image/tiff" => "tiff",
- "image/tiff-fx" => "tiff",
- "application/x-bittorrent" => "torrent",
- "text/tab-separated-values" => "tsv",
- "application/x-ustar" => "ustar",
- "application/x-cdlink" => "vcd",
- "model/vrml" => "wrl",
- "audio/x-wav" => "wav",
- "audio/x-ms-wax" => "wax",
- "image/vnd.wap.wbmp" => "wbmp",
- "application/vnd.wap.wbxml" => "wbxml",
- "video/x-ms-wm" => "wm",
- "audio/x-ms-wma" => "wma",
- "text/vnd.wap.wml" => "wml",
- "application/vnd.wap.wmlc" => "wmlc",
- "text/vnd.wap.wmlscript" => "wmls",
- "application/vnd.wap.wmlscriptc" => "wmlsc",
- "video/x-ms-wmv" => "wmv",
- "video/x-ms-wmx" => "wmx",
- "video/x-ms-wvx" => "wvx",
- "image/x-xbitmap" => "xbm",
- "application/xhtml+xml" => "xhtml",
- "application/xml" => "xml",
- "image/x-xpixmap" => "xpm",
- "text/xsl" => "xsl",
- "image/x-xwindowdump" => "xwd",
- "chemical/x-xyz" => "xyz",
- "application/zip" => "zip",
- "application/msword" => "doc",
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => "docx",
- "application/vnd.openxmlformats-officedocument.wordprocessingml.template" => "dotx",
- "application/vnd.ms-word.document.macroEnabled.12" => "docm",
- "application/vnd.ms-excel" => "xls",
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => "xlsx",
- "application/vnd.openxmlformats-officedocument.spreadsheetml.template" => "xltx",
- "application/vnd.ms-excel.sheet.macroEnabled.12" => "xlsm",
- "application/vnd.ms-excel.template.macroEnabled.12" => "xltm",
- "application/vnd.ms-excel.addin.macroEnabled.12" => "xlam",
- "application/vnd.ms-excel.sheet.binary.macroEnabled.12" => "xlsb",
- "application/vnd.openxmlformats-officedocument.presentationml.presentation" => "pptx",
- "application/vnd.openxmlformats-officedocument.presentationml.template" => "potx",
- "application/vnd.openxmlformats-officedocument.presentationml.slideshow" => "ppsx",
- "application/vnd.ms-powerpoint.addin.macroEnabled.12" => "ppam",
- "application/vnd.ms-powerpoint.presentation.macroEnabled.12" => "pptm",
- "application/vnd.ms-powerpoint.template.macroEnabled.12" => "potm",
- "application/vnd.ms-powerpoint.slideshow.macroEnabled.12" => "ppsm",
+ "application/postscript" => "ps",
+ "audio/x-aiff" => "aiff",
+ "text/plain" => "txt",
+ "video/x-ms-asf" => "asx",
+ "audio/basic" => "snd",
+ "video/x-msvideo" => "avi",
+ "application/x-bcpio" => "bcpio",
+ "application/octet-stream" => "so",
+ "image/bmp" => "bmp",
+ "application/x-rar" => "rar",
+ "application/x-bzip2" => "bz2",
+ "application/x-netcdf" => "nc",
+ "application/x-kchart" => "chrt",
+ "application/x-cpio" => "cpio",
+ "application/mac-compactpro" => "cpt",
+ "application/x-csh" => "csh",
+ "text/css" => "css",
+ "text/csv" => "csv",
+ "application/x-director" => "dxr",
+ "image/vnd.djvu" => "djvu",
+ "application/x-dvi" => "dvi",
+ "image/vnd.dwg" => "dwg",
+ "application/epub" => "epub",
+ "application/epub+zip" => "epub",
+ "text/x-setext" => "etx",
+ "application/andrew-inset" => "ez",
+ "video/x-flv" => "flv",
+ "image/gif" => "gif",
+ "application/x-gtar" => "gtar",
+ "application/x-gzip" => "tgz",
+ "application/x-hdf" => "hdf",
+ "application/mac-binhex40" => "hqx",
+ "text/html" => "html",
+ "text/htm" => "htm",
+ "x-conference/x-cooltalk" => "ice",
+ "image/ief" => "ief",
+ "model/iges" => "igs",
+ "text/vnd.sun.j2me.app-descriptor" => "jad",
+ "application/x-java-archive" => "jar",
+ "application/x-java-jnlp-file" => "jnlp",
+ "image/jpeg" => "jpg",
+ "application/x-javascript" => "js",
+ "audio/midi" => "midi",
+ "application/x-killustrator" => "kil",
+ "application/x-kpresenter" => "kpt",
+ "application/x-kspread" => "ksp",
+ "application/x-kword" => "kwt",
+ "application/vnd.google-earth.kml+xml" => "kml",
+ "application/vnd.google-earth.kmz" => "kmz",
+ "application/x-latex" => "latex",
+ "audio/x-mpegurl" => "m3u",
+ "application/x-troff-man" => "man",
+ "application/x-troff-me" => "me",
+ "model/mesh" => "silo",
+ "application/vnd.mif" => "mif",
+ "video/quicktime" => "mov",
+ "video/x-sgi-movie" => "movie",
+ "audio/mpeg" => "mp3",
+ "video/mp4" => "mp4",
+ "video/mpeg" => "mpeg",
+ "application/x-troff-ms" => "ms",
+ "video/vnd.mpegurl" => "mxu",
+ "application/vnd.oasis.opendocument.database" => "odb",
+ "application/vnd.oasis.opendocument.chart" => "odc",
+ "application/vnd.oasis.opendocument.formula" => "odf",
+ "application/vnd.oasis.opendocument.graphics" => "odg",
+ "application/vnd.oasis.opendocument.image" => "odi",
+ "application/vnd.oasis.opendocument.text-master" => "odm",
+ "application/vnd.oasis.opendocument.presentation" => "odp",
+ "application/vnd.oasis.opendocument.spreadsheet" => "ods",
+ "application/vnd.oasis.opendocument.text" => "odt",
+ "application/ogg" => "ogg",
+ "video/ogg" => "ogv",
+ "application/vnd.oasis.opendocument.graphics-template" => "otg",
+ "application/vnd.oasis.opendocument.text-web" => "oth",
+ "application/vnd.oasis.opendocument.presentation-template" => "otp",
+ "application/vnd.oasis.opendocument.spreadsheet-template" => "ots",
+ "application/vnd.oasis.opendocument.text-template" => "ott",
+ "image/x-portable-bitmap" => "pbm",
+ "chemical/x-pdb" => "pdb",
+ "application/pdf" => "pdf",
+ "image/x-portable-graymap" => "pgm",
+ "application/x-chess-pgn" => "pgn",
+ "text/x-php" => "php",
+ "image/png" => "png",
+ "image/x-portable-anymap" => "pnm",
+ "image/x-portable-pixmap" => "ppm",
+ "application/vnd.ms-powerpoint" => "ppt",
+ "audio/x-realaudio" => "ra",
+ "audio/x-pn-realaudio" => "rm",
+ "image/x-cmu-raster" => "ras",
+ "image/x-rgb" => "rgb",
+ "application/x-troff" => "tr",
+ "application/x-rpm" => "rpm",
+ "text/rtf" => "rtf",
+ "text/richtext" => "rtx",
+ "text/sgml" => "sgml",
+ "application/x-sh" => "sh",
+ "application/x-shar" => "shar",
+ "application/vnd.symbian.install" => "sis",
+ "application/x-stuffit" => "sit",
+ "application/x-koan" => "skt",
+ "application/smil" => "smil",
+ "image/svg+xml" => "svg",
+ "application/x-futuresplash" => "spl",
+ "application/x-wais-source" => "src",
+ "application/vnd.sun.xml.calc.template" => "stc",
+ "application/vnd.sun.xml.draw.template" => "std",
+ "application/vnd.sun.xml.impress.template" => "sti",
+ "application/vnd.sun.xml.writer.template" => "stw",
+ "application/x-sv4cpio" => "sv4cpio",
+ "application/x-sv4crc" => "sv4crc",
+ "application/x-shockwave-flash" => "swf",
+ "application/vnd.sun.xml.calc" => "sxc",
+ "application/vnd.sun.xml.draw" => "sxd",
+ "application/vnd.sun.xml.writer.global" => "sxg",
+ "application/vnd.sun.xml.impress" => "sxi",
+ "application/vnd.sun.xml.math" => "sxm",
+ "application/vnd.sun.xml.writer" => "sxw",
+ "application/x-tar" => "tar",
+ "application/x-tcl" => "tcl",
+ "application/x-tex" => "tex",
+ "application/x-texinfo" => "texinfo",
+ "image/tiff" => "tiff",
+ "image/tiff-fx" => "tiff",
+ "application/x-bittorrent" => "torrent",
+ "text/tab-separated-values" => "tsv",
+ "application/x-ustar" => "ustar",
+ "application/x-cdlink" => "vcd",
+ "model/vrml" => "wrl",
+ "audio/x-wav" => "wav",
+ "audio/x-ms-wax" => "wax",
+ "image/vnd.wap.wbmp" => "wbmp",
+ "application/vnd.wap.wbxml" => "wbxml",
+ "video/webm" => "webm",
+ "image/webp" => "webp",
+ "video/x-ms-wm" => "wm",
+ "audio/x-ms-wma" => "wma",
+ "text/vnd.wap.wml" => "wml",
+ "application/vnd.wap.wmlc" => "wmlc",
+ "text/vnd.wap.wmlscript" => "wmls",
+ "application/vnd.wap.wmlscriptc" => "wmlsc",
+ "video/x-ms-wmv" => "wmv",
+ "video/x-ms-wmx" => "wmx",
+ "video/x-ms-wvx" => "wvx",
+ "image/x-xbitmap" => "xbm",
+ "application/xhtml+xml" => "xhtml",
+ "application/xml" => "xml",
+ "image/x-xpixmap" => "xpm",
+ "text/xsl" => "xsl",
+ "image/x-xwindowdump" => "xwd",
+ "chemical/x-xyz" => "xyz",
+ "application/zip" => "zip",
+ "application/msword" => "doc",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => "docx",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template" => "dotx",
+ "application/vnd.ms-word.document.macroEnabled.12" => "docm",
+ "application/vnd.ms-excel" => "xls",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => "xlsx",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template" => "xltx",
+ "application/vnd.ms-excel.sheet.macroEnabled.12" => "xlsm",
+ "application/vnd.ms-excel.template.macroEnabled.12" => "xltm",
+ "application/vnd.ms-excel.addin.macroEnabled.12" => "xlam",
+ "application/vnd.ms-excel.sheet.binary.macroEnabled.12" => "xlsb",
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation" => "pptx",
+ "application/vnd.openxmlformats-officedocument.presentationml.template" => "potx",
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow" => "ppsx",
+ "application/vnd.ms-powerpoint.addin.macroEnabled.12" => "ppam",
+ "application/vnd.ms-powerpoint.presentation.macroEnabled.12" => "pptm",
+ "application/vnd.ms-powerpoint.template.macroEnabled.12" => "potm",
+ "application/vnd.ms-powerpoint.slideshow.macroEnabled.12" => "ppsm",
);
if ( ! function_exists('get_extension_from_mime'))
{
- function get_extension_from_mime($mime){
- global $mime_types;
- if(strpos($mime, ';')!==FALSE){
- $mime = substr($mime, 0,strpos($mime, ';'));
- }
- if(isset($mime_types[$mime])){
- return $mime_types[$mime];
- }
- return '';
- }
+ function get_extension_from_mime($mime){
+ global $mime_types;
+ if(strpos($mime, ';')!==FALSE){
+ $mime = substr($mime, 0,strpos($mime, ';'));
+ }
+ if(isset($mime_types[$mime])){
+ return $mime_types[$mime];
+ }
+ return '';
+ }
}
if ( ! function_exists('get_file_mime_type'))
{
- function get_file_mime_type($filename, $debug = false)
- {
- if (function_exists('finfo_open') && function_exists('finfo_file') && function_exists('finfo_close'))
- {
- $fileinfo = finfo_open(FILEINFO_MIME_TYPE);
- $mime_type = finfo_file($fileinfo, $filename);
- finfo_close($fileinfo);
+ function get_file_mime_type($filename, $debug = false)
+ {
+ if (function_exists('finfo_open') && function_exists('finfo_file') && function_exists('finfo_close'))
+ {
+ $fileinfo = finfo_open(FILEINFO_MIME_TYPE);
+ $mime_type = finfo_file($fileinfo, $filename);
+ finfo_close($fileinfo);
- if ( ! empty($mime_type))
- {
- if (true === $debug)
- {
- return array( 'mime_type' => $mime_type, 'method' => 'fileinfo' );
- }
+ if ( ! empty($mime_type))
+ {
+ if (true === $debug)
+ {
+ return array( 'mime_type' => $mime_type, 'method' => 'fileinfo' );
+ }
- return $mime_type;
- }
- }
+ return $mime_type;
+ }
+ }
- if (function_exists('mime_content_type'))
- {
- $mime_type = mime_content_type($filename);
+ if (function_exists('mime_content_type'))
+ {
+ $mime_type = mime_content_type($filename);
- if ( ! empty($mime_type))
- {
- if (true === $debug)
- {
- return array( 'mime_type' => $mime_type, 'method' => 'mime_content_type' );
- }
+ if ( ! empty($mime_type))
+ {
+ if (true === $debug)
+ {
+ return array( 'mime_type' => $mime_type, 'method' => 'mime_content_type' );
+ }
- return $mime_type;
- }
- }
+ return $mime_type;
+ }
+ }
- global $mime_types;
- $mime_types = array_flip($mime_types);
+ global $mime_types;
+ $mime_types = array_flip($mime_types);
- $tmp_array = explode('.', $filename);
- $ext = strtolower(array_pop($tmp_array));
+ $tmp_array = explode('.', $filename);
+ $ext = strtolower(array_pop($tmp_array));
- if ( ! empty($mime_types[ $ext ]))
- {
- if (true === $debug)
- {
- return array( 'mime_type' => $mime_types[ $ext ], 'method' => 'from_array' );
- }
+ if ( ! empty($mime_types[ $ext ]))
+ {
+ if (true === $debug)
+ {
+ return array( 'mime_type' => $mime_types[ $ext ], 'method' => 'from_array' );
+ }
- return $mime_types[ $ext ];
- }
+ return $mime_types[ $ext ];
+ }
- if (true === $debug)
- {
- return array( 'mime_type' => 'application/octet-stream', 'method' => 'last_resort' );
- }
+ if (true === $debug)
+ {
+ return array( 'mime_type' => 'application/octet-stream', 'method' => 'last_resort' );
+ }
- return 'application/octet-stream';
- }
+ return 'application/octet-stream';
+ }
}
diff --git a/core/vendor/filemanager/include/php_image_magician.php b/core/vendor/filemanager/include/php_image_magician.php
index 8dbc5e77..9ec8e001 100644
--- a/core/vendor/filemanager/include/php_image_magician.php
+++ b/core/vendor/filemanager/include/php_image_magician.php
@@ -162,88 +162,87 @@
class imageLib {
- private $fileName;
- private $image;
- protected $imageResized;
- private $widthOriginal; # Always be the original width
- private $heightOriginal;
- private $width; # Current width (width after resize)
- private $height;
- private $imageSize;
- private $fileExtension;
+ private $fileName;
+ private $image;
+ protected $imageResized;
+ private $widthOriginal; # Always be the original width
+ private $heightOriginal;
+ private $width; # Current width (width after resize)
+ private $height;
+ private $imageSize;
+ private $fileExtension;
- private $debug = true;
- private $errorArray = array();
+ private $debug = true;
+ private $errorArray = array();
- private $forceStretch = true;
- private $aggresiveSharpening = false;
+ private $forceStretch = true;
+ private $aggresiveSharpening = false;
- private $transparentArray = array( '.png', '.gif' );
- private $keepTransparency = true;
- private $fillColorArray = array( 'r' => 255, 'g' => 255, 'b' => 255 );
+ private $transparentArray = array( '.png', '.gif' );
+ private $keepTransparency = true;
+ private $fillColorArray = array( 'r' => 255, 'g' => 255, 'b' => 255 );
- private $sharpenArray = array( 'jpg' );
+ private $sharpenArray = array( 'jpg' );
- private $psdReaderPath;
- private $filterOverlayPath;
+ private $psdReaderPath;
+ private $filterOverlayPath;
- private $isInterlace;
+ private $isInterlace;
- private $captionBoxPositionArray = array();
+ private $captionBoxPositionArray = array();
- private $fontDir = 'fonts';
+ private $fontDir = 'fonts';
- private $cropFromTopPercent = 10;
+ private $cropFromTopPercent = 10;
## --------------------------------------------------------
- function __construct($fileName)
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose: Constructor
- # Param in: $fileName: File name and path.
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- if ( ! $this->testGDInstalled())
- {
- if ($this->debug)
- {
- throw new Exception('The GD Library is not installed.');
- }
- else
- {
- throw new Exception();
- }
- };
+ function __construct($fileName)
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose: Constructor
+ # Param in: $fileName: File name and path.
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ if ( ! $this->testGDInstalled())
+ {
+ if ($this->debug)
+ {
+ throw new Exception('The GD Library is not installed.');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ };
- $this->initialise();
+ $this->initialise();
- // *** Save the image file name. Only store this incase you want to display it
- $this->fileName = $fileName;
- $this->fileExtension = fix_strtolower(strrchr($fileName, '.'));
+ // *** Save the image file name. Only store this incase you want to display it
+ $this->fileName = $fileName;
+ $this->fileExtension = fix_strtolower(strrchr($fileName, '.'));
- // *** Open up the file
- $this->image = $this->openImage($fileName);
+ // *** Open up the file
+ $this->image = $this->openImage($fileName);
+
+ // *** Assign here so we don't modify the original
+ $this->imageResized = $this->image;
+
+ // *** If file is an image
+ if ($this->testIsImage($this->image))
+ {
+ // *** Get width and height
+ $this->width = imagesx($this->image);
+ $this->widthOriginal = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ $this->heightOriginal = imagesy($this->image);
- // *** Assign here so we don't modify the original
- $this->imageResized = $this->image;
-
- // *** If file is an image
- if ($this->testIsImage($this->image))
- {
- // *** Get width and height
- $this->width = imagesx($this->image);
- $this->widthOriginal = imagesx($this->image);
- $this->height = imagesy($this->image);
- $this->heightOriginal = imagesy($this->image);
-
-
- /* Added 15-09-08
+ /* Added 15-09-08
* Get the filesize using this build in method.
* Stores an array of size
*
@@ -252,725 +251,725 @@ class imageLib {
* $this->imageSize[3] = width x height
*
*/
- $this->imageSize = getimagesize($this->fileName);
+ $this->imageSize = getimagesize($this->fileName);
- }
- else
- {
- $this->errorArray[] = 'File is not an image';
- }
- }
+ }
+ else
+ {
+ $this->errorArray[] = 'File is not an image';
+ }
+ }
## --------------------------------------------------------
- private function initialise()
- {
+ private function initialise()
+ {
- $this->psdReaderPath = dirname(__FILE__) . '/classPhpPsdReader.php';
- $this->filterOverlayPath = dirname(__FILE__) . '/filters';
+ $this->psdReaderPath = dirname(__FILE__) . '/classPhpPsdReader.php';
+ $this->filterOverlayPath = dirname(__FILE__) . '/filters';
- // *** Set if image should be interlaced or not.
- $this->isInterlace = false;
- }
+ // *** Set if image should be interlaced or not.
+ $this->isInterlace = false;
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Resize
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function resizeImage($newWidth, $newHeight, $option = 0, $sharpen = false, $autoRotate = false)
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose: Resizes the image
- # Param in: $newWidth:
- # $newHeight:
- # $option: 0 / exact = defined size;
- # 1 / portrait = keep aspect set height;
- # 2 / landscape = keep aspect set width;
- # 3 / auto = auto;
- # 4 / crop= resize and crop;
- #
- # $option can also be an array containing options for
- # cropping. E.G., array('crop', 'r')
- #
- # This array only applies to 'crop' and the 'r' refers to
- # "crop right". Other value include; tl, t, tr, l, m (default),
- # r, bl, b, br, or you can specify your own co-ords (which
- # isn't recommended.
- #
- # $sharpen: true: sharpen (jpg only);
- # false: don't sharpen
- # Param out: n/a
- # Reference:
- # Notes: To clarify the $option input:
- # 0 = The exact height and width dimensions you set.
- # 1 = Whatever height is passed in will be the height that
- # is set. The width will be calculated and set automatically
- # to a the value that keeps the original aspect ratio.
- # 2 = The same but based on the width. We try make the image the
- # biggest size we can while stil fitting inside the box size
- # 3 = Depending whether the image is landscape or portrait, this
- # will automatically determine whether to resize via
- # dimension 1,2 or 0
- # 4 = Will resize and then crop the image for best fit
- #
- # forceStretch can be applied to options 1,2,3 and 4
- #
- {
+ public function resizeImage($newWidth, $newHeight, $option = 0, $sharpen = false, $autoRotate = false)
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose: Resizes the image
+ # Param in: $newWidth:
+ # $newHeight:
+ # $option: 0 / exact = defined size;
+ # 1 / portrait = keep aspect set height;
+ # 2 / landscape = keep aspect set width;
+ # 3 / auto = auto;
+ # 4 / crop= resize and crop;
+ #
+ # $option can also be an array containing options for
+ # cropping. E.G., array('crop', 'r')
+ #
+ # This array only applies to 'crop' and the 'r' refers to
+ # "crop right". Other value include; tl, t, tr, l, m (default),
+ # r, bl, b, br, or you can specify your own co-ords (which
+ # isn't recommended.
+ #
+ # $sharpen: true: sharpen (jpg only);
+ # false: don't sharpen
+ # Param out: n/a
+ # Reference:
+ # Notes: To clarify the $option input:
+ # 0 = The exact height and width dimensions you set.
+ # 1 = Whatever height is passed in will be the height that
+ # is set. The width will be calculated and set automatically
+ # to a the value that keeps the original aspect ratio.
+ # 2 = The same but based on the width. We try make the image the
+ # biggest size we can while stil fitting inside the box size
+ # 3 = Depending whether the image is landscape or portrait, this
+ # will automatically determine whether to resize via
+ # dimension 1,2 or 0
+ # 4 = Will resize and then crop the image for best fit
+ #
+ # forceStretch can be applied to options 1,2,3 and 4
+ #
+ {
- // *** We can pass in an array of options to change the crop position
- $cropPos = 'm';
- if (is_array($option) && fix_strtolower($option[0]) == 'crop')
- {
- $cropPos = $option[1]; # get the crop option
- }
- else
- {
- if (strpos($option, '-') !== false)
- {
- // *** Or pass in a hyphen seperated option
- $optionPiecesArray = explode('-', $option);
- $cropPos = end($optionPiecesArray);
- }
- }
+ // *** We can pass in an array of options to change the crop position
+ $cropPos = 'm';
+ if (is_array($option) && fix_strtolower($option[0]) == 'crop')
+ {
+ $cropPos = $option[1]; # get the crop option
+ }
+ else
+ {
+ if (strpos($option, '-') !== false)
+ {
+ // *** Or pass in a hyphen seperated option
+ $optionPiecesArray = explode('-', $option);
+ $cropPos = end($optionPiecesArray);
+ }
+ }
- // *** Check the option is valid
- $option = $this->prepOption($option);
+ // *** Check the option is valid
+ $option = $this->prepOption($option);
- // *** Make sure the file passed in is valid
- if ( ! $this->image)
- {
- if ($this->debug)
- {
- throw new Exception('file ' . $this->getFileName() . ' is missing or invalid');
- }
- else
- {
- throw new Exception();
- }
- };
+ // *** Make sure the file passed in is valid
+ if ( ! $this->image)
+ {
+ if ($this->debug)
+ {
+ throw new Exception('file ' . $this->getFileName() . ' is missing or invalid');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ };
- // *** Get optimal width and height - based on $option
- $dimensionsArray = $this->getDimensions($newWidth, $newHeight, $option);
+ // *** Get optimal width and height - based on $option
+ $dimensionsArray = $this->getDimensions($newWidth, $newHeight, $option);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
- // *** Resample - create image canvas of x, y size
- $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
- $this->keepTransparancy($optimalWidth, $optimalHeight, $this->imageResized);
- imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
+ // *** Resample - create image canvas of x, y size
+ $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
+ $this->keepTransparancy($optimalWidth, $optimalHeight, $this->imageResized);
+ imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
- // *** If '4', then crop too
- if ($option == 4 || $option == 'crop')
- {
+ // *** If '4', then crop too
+ if ($option == 4 || $option == 'crop')
+ {
- if (($optimalWidth >= $newWidth && $optimalHeight >= $newHeight))
- {
- $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
- }
- }
+ if (($optimalWidth >= $newWidth && $optimalHeight >= $newHeight))
+ {
+ $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
+ }
+ }
- // *** If Rotate.
- if ($autoRotate)
- {
+ // *** If Rotate.
+ if ($autoRotate)
+ {
- $exifData = $this->getExif(false);
- if (count($exifData) > 0)
- {
+ $exifData = $this->getExif(false);
+ if (count($exifData) > 0)
+ {
- switch ($exifData['orientation'])
- {
- case 8:
- $this->imageResized = imagerotate($this->imageResized, 90, 0);
- break;
- case 3:
- $this->imageResized = imagerotate($this->imageResized, 180, 0);
- break;
- case 6:
- $this->imageResized = imagerotate($this->imageResized, -90, 0);
- break;
- }
- }
- }
+ switch ($exifData['orientation'])
+ {
+ case 8:
+ $this->imageResized = imagerotate($this->imageResized, 90, 0);
+ break;
+ case 3:
+ $this->imageResized = imagerotate($this->imageResized, 180, 0);
+ break;
+ case 6:
+ $this->imageResized = imagerotate($this->imageResized, -90, 0);
+ break;
+ }
+ }
+ }
- // *** Sharpen image (if jpg and the user wishes to do so)
- if ($sharpen && in_array($this->fileExtension, $this->sharpenArray))
- {
+ // *** Sharpen image (if jpg and the user wishes to do so)
+ if ($sharpen && in_array($this->fileExtension, $this->sharpenArray))
+ {
- // *** Sharpen
- $this->sharpen();
- }
- }
+ // *** Sharpen
+ $this->sharpen();
+ }
+ }
## --------------------------------------------------------
- public function cropImage($newWidth, $newHeight, $cropPos = 'm')
- # Author: Jarrod Oberto
- # Date: 08-09-11
- # Purpose: Crops the image
- # Param in: $newWidth: crop with
- # $newHeight: crop height
- # $cropPos: Can be any of the following:
- # tl, t, tr, l, m, r, bl, b, br, auto
- # Or:
- # a custom position such as '30x50'
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
+ public function cropImage($newWidth, $newHeight, $cropPos = 'm')
+ # Author: Jarrod Oberto
+ # Date: 08-09-11
+ # Purpose: Crops the image
+ # Param in: $newWidth: crop with
+ # $newHeight: crop height
+ # $cropPos: Can be any of the following:
+ # tl, t, tr, l, m, r, bl, b, br, auto
+ # Or:
+ # a custom position such as '30x50'
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
- // *** Make sure the file passed in is valid
- if ( ! $this->image)
- {
- if ($this->debug)
- {
- throw new Exception('file ' . $this->getFileName() . ' is missing or invalid');
- }
- else
- {
- throw new Exception();
- }
- };
+ // *** Make sure the file passed in is valid
+ if ( ! $this->image)
+ {
+ if ($this->debug)
+ {
+ throw new Exception('file ' . $this->getFileName() . ' is missing or invalid');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ };
- $this->imageResized = $this->image;
- $this->crop($this->width, $this->height, $newWidth, $newHeight, $cropPos);
+ $this->imageResized = $this->image;
+ $this->crop($this->width, $this->height, $newWidth, $newHeight, $cropPos);
- }
+ }
## --------------------------------------------------------
- private function keepTransparancy($width, $height, $im)
- # Author: Jarrod Oberto
- # Date: 08-04-11
- # Purpose: Keep transparency for png and gif image
- # Param in:
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- // *** If PNG, perform some transparency retention actions (gif untested)
- if (in_array($this->fileExtension, $this->transparentArray) && $this->keepTransparency)
- {
- imagealphablending($im, false);
- imagesavealpha($im, true);
- $transparent = imagecolorallocatealpha($im, 255, 255, 255, 127);
- imagefilledrectangle($im, 0, 0, $width, $height, $transparent);
- }
- else
- {
- $color = imagecolorallocate($im, $this->fillColorArray['r'], $this->fillColorArray['g'], $this->fillColorArray['b']);
- imagefilledrectangle($im, 0, 0, $width, $height, $color);
- }
- }
+ private function keepTransparancy($width, $height, $im)
+ # Author: Jarrod Oberto
+ # Date: 08-04-11
+ # Purpose: Keep transparency for png and gif image
+ # Param in:
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ // *** If PNG, perform some transparency retention actions (gif untested)
+ if (in_array($this->fileExtension, $this->transparentArray) && $this->keepTransparency)
+ {
+ imagealphablending($im, false);
+ imagesavealpha($im, true);
+ $transparent = imagecolorallocatealpha($im, 255, 255, 255, 127);
+ imagefilledrectangle($im, 0, 0, $width, $height, $transparent);
+ }
+ else
+ {
+ $color = imagecolorallocate($im, $this->fillColorArray['r'], $this->fillColorArray['g'], $this->fillColorArray['b']);
+ imagefilledrectangle($im, 0, 0, $width, $height, $color);
+ }
+ }
## --------------------------------------------------------
- private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos)
- # Author: Jarrod Oberto
- # Date: 15-09-08
- # Purpose: Crops the image
- # Param in: $newWidth:
- # $newHeight:
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
+ private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos)
+ # Author: Jarrod Oberto
+ # Date: 15-09-08
+ # Purpose: Crops the image
+ # Param in: $newWidth:
+ # $newHeight:
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
- // *** Get cropping co-ordinates
- $cropArray = $this->getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
- $cropStartX = $cropArray['x'];
- $cropStartY = $cropArray['y'];
+ // *** Get cropping co-ordinates
+ $cropArray = $this->getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
+ $cropStartX = $cropArray['x'];
+ $cropStartY = $cropArray['y'];
- // *** Crop this bad boy
- $crop = imagecreatetruecolor($newWidth, $newHeight);
- $this->keepTransparancy($optimalWidth, $optimalHeight, $crop);
- imagecopyresampled($crop, $this->imageResized, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight);
+ // *** Crop this bad boy
+ $crop = imagecreatetruecolor($newWidth, $newHeight);
+ $this->keepTransparancy($optimalWidth, $optimalHeight, $crop);
+ imagecopyresampled($crop, $this->imageResized, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight);
- $this->imageResized = $crop;
+ $this->imageResized = $crop;
- // *** Set new width and height to our variables
- $this->width = $newWidth;
- $this->height = $newHeight;
+ // *** Set new width and height to our variables
+ $this->width = $newWidth;
+ $this->height = $newHeight;
- }
+ }
## --------------------------------------------------------
- private function getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $pos = 'm')
- #
- # Author: Jarrod Oberto
- # Date: July 11
- # Purpose: Set the cropping area.
- # Params in:
- # Params out: (array) the crop x and y co-ordinates.
- # Notes: When specifying the exact pixel crop position (eg 10x15), be
- # very careful as it's easy to crop out of the image leaving
- # black borders.
- #
- {
- $pos = fix_strtolower($pos);
+ private function getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $pos = 'm')
+ #
+ # Author: Jarrod Oberto
+ # Date: July 11
+ # Purpose: Set the cropping area.
+ # Params in:
+ # Params out: (array) the crop x and y co-ordinates.
+ # Notes: When specifying the exact pixel crop position (eg 10x15), be
+ # very careful as it's easy to crop out of the image leaving
+ # black borders.
+ #
+ {
+ $pos = fix_strtolower($pos);
- // *** If co-ords have been entered
- if (strstr($pos, 'x'))
- {
- $pos = str_replace(' ', '', $pos);
+ // *** If co-ords have been entered
+ if (strstr($pos, 'x'))
+ {
+ $pos = str_replace(' ', '', $pos);
- $xyArray = explode('x', $pos);
- list($cropStartX, $cropStartY) = $xyArray;
+ $xyArray = explode('x', $pos);
+ list($cropStartX, $cropStartY) = $xyArray;
- }
- else
- {
+ }
+ else
+ {
- switch ($pos)
- {
- case 'tl':
- $cropStartX = 0;
- $cropStartY = 0;
- break;
+ switch ($pos)
+ {
+ case 'tl':
+ $cropStartX = 0;
+ $cropStartY = 0;
+ break;
- case 't':
- $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
- $cropStartY = 0;
- break;
+ case 't':
+ $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
+ $cropStartY = 0;
+ break;
- case 'tr':
- $cropStartX = $optimalWidth - $newWidth;
- $cropStartY = 0;
- break;
+ case 'tr':
+ $cropStartX = $optimalWidth - $newWidth;
+ $cropStartY = 0;
+ break;
- case 'l':
- $cropStartX = 0;
- $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
- break;
+ case 'l':
+ $cropStartX = 0;
+ $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
+ break;
- case 'm':
- $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
- $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
- break;
+ case 'm':
+ $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
+ $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
+ break;
- case 'r':
- $cropStartX = $optimalWidth - $newWidth;
- $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
- break;
+ case 'r':
+ $cropStartX = $optimalWidth - $newWidth;
+ $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
+ break;
- case 'bl':
- $cropStartX = 0;
- $cropStartY = $optimalHeight - $newHeight;
- break;
+ case 'bl':
+ $cropStartX = 0;
+ $cropStartY = $optimalHeight - $newHeight;
+ break;
- case 'b':
- $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
- $cropStartY = $optimalHeight - $newHeight;
- break;
+ case 'b':
+ $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
+ $cropStartY = $optimalHeight - $newHeight;
+ break;
- case 'br':
- $cropStartX = $optimalWidth - $newWidth;
- $cropStartY = $optimalHeight - $newHeight;
- break;
+ case 'br':
+ $cropStartX = $optimalWidth - $newWidth;
+ $cropStartY = $optimalHeight - $newHeight;
+ break;
- case 'auto':
- // *** If image is a portrait crop from top, not center. v1.5
- if ($optimalHeight > $optimalWidth)
- {
- $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
- $cropStartY = ($this->cropFromTopPercent / 100) * $optimalHeight;
- }
- else
- {
+ case 'auto':
+ // *** If image is a portrait crop from top, not center. v1.5
+ if ($optimalHeight > $optimalWidth)
+ {
+ $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
+ $cropStartY = ($this->cropFromTopPercent / 100) * $optimalHeight;
+ }
+ else
+ {
- // *** Else crop from the center
- $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
- $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
- }
- break;
+ // *** Else crop from the center
+ $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
+ $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
+ }
+ break;
- default:
- // *** Default to center
- $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
- $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
- break;
- }
- }
+ default:
+ // *** Default to center
+ $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
+ $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
+ break;
+ }
+ }
- return array( 'x' => $cropStartX, 'y' => $cropStartY );
- }
+ return array( 'x' => $cropStartX, 'y' => $cropStartY );
+ }
## --------------------------------------------------------
- private function getDimensions($newWidth, $newHeight, $option)
- # Author: Jarrod Oberto
- # Date: 17-11-09
- # Purpose: Get new image dimensions based on user specificaions
- # Param in: $newWidth:
- # $newHeight:
- # Param out: Array of new width and height values
- # Reference:
- # Notes: If $option = 3 then this function is call recursivly
- #
- # To clarify the $option input:
- # 0 = The exact height and width dimensions you set.
- # 1 = Whatever height is passed in will be the height that
- # is set. The width will be calculated and set automatically
- # to a the value that keeps the original aspect ratio.
- # 2 = The same but based on the width.
- # 3 = Depending whether the image is landscape or portrait, this
- # will automatically determine whether to resize via
- # dimension 1,2 or 0.
- # 4 = Resize the image as much as possible, then crop the
- # remainder.
- {
+ private function getDimensions($newWidth, $newHeight, $option)
+ # Author: Jarrod Oberto
+ # Date: 17-11-09
+ # Purpose: Get new image dimensions based on user specificaions
+ # Param in: $newWidth:
+ # $newHeight:
+ # Param out: Array of new width and height values
+ # Reference:
+ # Notes: If $option = 3 then this function is call recursivly
+ #
+ # To clarify the $option input:
+ # 0 = The exact height and width dimensions you set.
+ # 1 = Whatever height is passed in will be the height that
+ # is set. The width will be calculated and set automatically
+ # to a the value that keeps the original aspect ratio.
+ # 2 = The same but based on the width.
+ # 3 = Depending whether the image is landscape or portrait, this
+ # will automatically determine whether to resize via
+ # dimension 1,2 or 0.
+ # 4 = Resize the image as much as possible, then crop the
+ # remainder.
+ {
- switch (strval($option))
- {
- case '0':
- case 'exact':
- $optimalWidth = $newWidth;
- $optimalHeight = $newHeight;
- break;
- case '1':
- case 'portrait':
- $dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- break;
- case '2':
- case 'landscape':
- $dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- break;
- case '3':
- case 'auto':
- $dimensionsArray = $this->getSizeByAuto($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- break;
- case '4':
- case 'crop':
- $dimensionsArray = $this->getOptimalCrop($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- break;
- }
+ switch (strval($option))
+ {
+ case '0':
+ case 'exact':
+ $optimalWidth = $newWidth;
+ $optimalHeight = $newHeight;
+ break;
+ case '1':
+ case 'portrait':
+ $dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ break;
+ case '2':
+ case 'landscape':
+ $dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ break;
+ case '3':
+ case 'auto':
+ $dimensionsArray = $this->getSizeByAuto($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ break;
+ case '4':
+ case 'crop':
+ $dimensionsArray = $this->getOptimalCrop($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ break;
+ }
- return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
- }
+ return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
+ }
## --------------------------------------------------------
- private function getSizeByFixedHeight($newWidth, $newHeight)
- {
- // *** If forcing is off...
- if ( ! $this->forceStretch)
- {
+ private function getSizeByFixedHeight($newWidth, $newHeight)
+ {
+ // *** If forcing is off...
+ if ( ! $this->forceStretch)
+ {
- // *** ...check if actual height is less than target height
- if ($this->height < $newHeight)
- {
- return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
- }
- }
+ // *** ...check if actual height is less than target height
+ if ($this->height < $newHeight)
+ {
+ return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
+ }
+ }
- $ratio = $this->width / $this->height;
+ $ratio = $this->width / $this->height;
- $newWidth = $newHeight * $ratio;
+ $newWidth = $newHeight * $ratio;
- //return $newWidth;
- return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
- }
+ //return $newWidth;
+ return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
+ }
## --------------------------------------------------------
- private function getSizeByFixedWidth($newWidth, $newHeight)
- {
- // *** If forcing is off...
- if ( ! $this->forceStretch)
- {
+ private function getSizeByFixedWidth($newWidth, $newHeight)
+ {
+ // *** If forcing is off...
+ if ( ! $this->forceStretch)
+ {
- // *** ...check if actual width is less than target width
- if ($this->width < $newWidth)
- {
- return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
- }
- }
+ // *** ...check if actual width is less than target width
+ if ($this->width < $newWidth)
+ {
+ return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
+ }
+ }
- $ratio = $this->height / $this->width;
+ $ratio = $this->height / $this->width;
- $newHeight = $newWidth * $ratio;
+ $newHeight = $newWidth * $ratio;
- //return $newHeight;
- return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
- }
+ //return $newHeight;
+ return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
+ }
## --------------------------------------------------------
- private function getSizeByAuto($newWidth, $newHeight)
- # Author: Jarrod Oberto
- # Date: 19-08-08
- # Purpose: Depending on the height, choose to resize by 0, 1, or 2
- # Param in: The new height and new width
- # Notes:
- #
- {
- // *** If forcing is off...
- if ( ! $this->forceStretch)
- {
+ private function getSizeByAuto($newWidth, $newHeight)
+ # Author: Jarrod Oberto
+ # Date: 19-08-08
+ # Purpose: Depending on the height, choose to resize by 0, 1, or 2
+ # Param in: The new height and new width
+ # Notes:
+ #
+ {
+ // *** If forcing is off...
+ if ( ! $this->forceStretch)
+ {
- // *** ...check if actual size is less than target size
- if ($this->width < $newWidth && $this->height < $newHeight)
- {
- return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
- }
- }
+ // *** ...check if actual size is less than target size
+ if ($this->width < $newWidth && $this->height < $newHeight)
+ {
+ return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
+ }
+ }
- if ($this->height < $this->width)
- // *** Image to be resized is wider (landscape)
- {
- //$optimalWidth = $newWidth;
- //$optimalHeight= $this->getSizeByFixedWidth($newWidth);
+ if ($this->height < $this->width)
+ // *** Image to be resized is wider (landscape)
+ {
+ //$optimalWidth = $newWidth;
+ //$optimalHeight= $this->getSizeByFixedWidth($newWidth);
- $dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- }
- elseif ($this->height > $this->width)
- // *** Image to be resized is taller (portrait)
- {
- //$optimalWidth = $this->getSizeByFixedHeight($newHeight);
- //$optimalHeight= $newHeight;
+ $dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ }
+ elseif ($this->height > $this->width)
+ // *** Image to be resized is taller (portrait)
+ {
+ //$optimalWidth = $this->getSizeByFixedHeight($newHeight);
+ //$optimalHeight= $newHeight;
- $dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- }
- else
- // *** Image to be resizerd is a square
- {
+ $dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ }
+ else
+ // *** Image to be resizerd is a square
+ {
- if ($newHeight < $newWidth)
- {
- //$optimalWidth = $newWidth;
- //$optimalHeight= $this->getSizeByFixedWidth($newWidth);
- $dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- }
- else
- {
- if ($newHeight > $newWidth)
- {
- //$optimalWidth = $this->getSizeByFixedHeight($newHeight);
- //$optimalHeight= $newHeight;
- $dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
- $optimalWidth = $dimensionsArray['optimalWidth'];
- $optimalHeight = $dimensionsArray['optimalHeight'];
- }
- else
- {
- // *** Sqaure being resized to a square
- $optimalWidth = $newWidth;
- $optimalHeight = $newHeight;
- }
- }
- }
+ if ($newHeight < $newWidth)
+ {
+ //$optimalWidth = $newWidth;
+ //$optimalHeight= $this->getSizeByFixedWidth($newWidth);
+ $dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ }
+ else
+ {
+ if ($newHeight > $newWidth)
+ {
+ //$optimalWidth = $this->getSizeByFixedHeight($newHeight);
+ //$optimalHeight= $newHeight;
+ $dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
+ $optimalWidth = $dimensionsArray['optimalWidth'];
+ $optimalHeight = $dimensionsArray['optimalHeight'];
+ }
+ else
+ {
+ // *** Sqaure being resized to a square
+ $optimalWidth = $newWidth;
+ $optimalHeight = $newHeight;
+ }
+ }
+ }
- return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
- }
+ return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
+ }
## --------------------------------------------------------
- private function getOptimalCrop($newWidth, $newHeight)
- # Author: Jarrod Oberto
- # Date: 17-11-09
- # Purpose: Get optimal crop dimensions
- # Param in: width and height as requested by user (fig 3)
- # Param out: Array of optimal width and height (fig 2)
- # Reference:
- # Notes: The optimal width and height return are not the same as the
- # same as the width and height passed in. For example:
- #
- #
- # |-----------------| |------------| |-------|
- # | | => |**| |**| => | |
- # | | |**| |**| | |
- # | | |------------| |-------|
- # |-----------------|
- # original optimal crop
- # size size size
- # Fig 1 2 3
- #
- # 300 x 250 150 x 125 150 x 100
- #
- # The optimal size is the smallest size (that is closest to the crop size)
- # while retaining proportion/ratio.
- #
- # The crop size is the optimal size that has been cropped on one axis to
- # make the image the exact size specified by the user.
- #
- # * represent cropped area
- #
- {
+ private function getOptimalCrop($newWidth, $newHeight)
+ # Author: Jarrod Oberto
+ # Date: 17-11-09
+ # Purpose: Get optimal crop dimensions
+ # Param in: width and height as requested by user (fig 3)
+ # Param out: Array of optimal width and height (fig 2)
+ # Reference:
+ # Notes: The optimal width and height return are not the same as the
+ # same as the width and height passed in. For example:
+ #
+ #
+ # |-----------------| |------------| |-------|
+ # | | => |**| |**| => | |
+ # | | |**| |**| | |
+ # | | |------------| |-------|
+ # |-----------------|
+ # original optimal crop
+ # size size size
+ # Fig 1 2 3
+ #
+ # 300 x 250 150 x 125 150 x 100
+ #
+ # The optimal size is the smallest size (that is closest to the crop size)
+ # while retaining proportion/ratio.
+ #
+ # The crop size is the optimal size that has been cropped on one axis to
+ # make the image the exact size specified by the user.
+ #
+ # * represent cropped area
+ #
+ {
- // *** If forcing is off...
- if ( ! $this->forceStretch)
- {
+ // *** If forcing is off...
+ if ( ! $this->forceStretch)
+ {
- // *** ...check if actual size is less than target size
- if ($this->width < $newWidth && $this->height < $newHeight)
- {
- return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
- }
- }
+ // *** ...check if actual size is less than target size
+ if ($this->width < $newWidth && $this->height < $newHeight)
+ {
+ return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
+ }
+ }
- $heightRatio = $this->height / $newHeight;
- $widthRatio = $this->width / $newWidth;
+ $heightRatio = $this->height / $newHeight;
+ $widthRatio = $this->width / $newWidth;
- if ($heightRatio < $widthRatio)
- {
- $optimalRatio = $heightRatio;
- }
- else
- {
- $optimalRatio = $widthRatio;
- }
+ if ($heightRatio < $widthRatio)
+ {
+ $optimalRatio = $heightRatio;
+ }
+ else
+ {
+ $optimalRatio = $widthRatio;
+ }
- $optimalHeight = round($this->height / $optimalRatio);
- $optimalWidth = round($this->width / $optimalRatio);
+ $optimalHeight = round($this->height / $optimalRatio);
+ $optimalWidth = round($this->width / $optimalRatio);
- return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
- }
+ return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
+ }
## --------------------------------------------------------
- private function sharpen()
- # Author: Jarrod Oberto
- # Date: 08 04 2011
- # Purpose: Sharpen image
- # Param in: n/a
- # Param out: n/a
- # Reference:
- # Notes:
- # Credit: Incorporates Joe Lencioni (August 6, 2008) code
- {
+ private function sharpen()
+ # Author: Jarrod Oberto
+ # Date: 08 04 2011
+ # Purpose: Sharpen image
+ # Param in: n/a
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ # Credit: Incorporates Joe Lencioni (August 6, 2008) code
+ {
- if (version_compare(PHP_VERSION, '5.1.0') >= 0)
- {
+ if (version_compare(PHP_VERSION, '5.1.0') >= 0)
+ {
- // ***
- if ($this->aggresiveSharpening)
- { # A more aggressive sharpening solution
+ // ***
+ if ($this->aggresiveSharpening)
+ { # A more aggressive sharpening solution
- $sharpenMatrix = array( array( -1, -1, -1 ),
- array( -1, 16, -1 ),
- array( -1, -1, -1 ) );
- $divisor = 8;
- $offset = 0;
+ $sharpenMatrix = array( array( -1, -1, -1 ),
+ array( -1, 16, -1 ),
+ array( -1, -1, -1 ) );
+ $divisor = 8;
+ $offset = 0;
- imageconvolution($this->imageResized, $sharpenMatrix, $divisor, $offset);
- }
- else # More subtle and personally more desirable
- {
- $sharpness = $this->findSharp($this->widthOriginal, $this->width);
+ imageconvolution($this->imageResized, $sharpenMatrix, $divisor, $offset);
+ }
+ else # More subtle and personally more desirable
+ {
+ $sharpness = $this->findSharp($this->widthOriginal, $this->width);
- $sharpenMatrix = array(
- array( -1, -2, -1 ),
- array( -2, $sharpness + 12, -2 ), //Lessen the effect of a filter by increasing the value in the center cell
- array( -1, -2, -1 )
- );
- $divisor = $sharpness; // adjusts brightness
- $offset = 0;
- imageconvolution($this->imageResized, $sharpenMatrix, $divisor, $offset);
- }
- }
- else
- {
- if ($this->debug)
- {
- throw new Exception('Sharpening required PHP 5.1.0 or greater.');
- }
- }
- }
+ $sharpenMatrix = array(
+ array( -1, -2, -1 ),
+ array( -2, $sharpness + 12, -2 ), //Lessen the effect of a filter by increasing the value in the center cell
+ array( -1, -2, -1 )
+ );
+ $divisor = $sharpness; // adjusts brightness
+ $offset = 0;
+ imageconvolution($this->imageResized, $sharpenMatrix, $divisor, $offset);
+ }
+ }
+ else
+ {
+ if ($this->debug)
+ {
+ throw new Exception('Sharpening required PHP 5.1.0 or greater.');
+ }
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function sharpen2($level)
- {
- $sharpenMatrix = array(
- array( $level, $level, $level ),
- array( $level, (8 * $level) + 1, $level ), //Lessen the effect of a filter by increasing the value in the center cell
- array( $level, $level, $level )
- );
+ private function sharpen2($level)
+ {
+ $sharpenMatrix = array(
+ array( $level, $level, $level ),
+ array( $level, (8 * $level) + 1, $level ), //Lessen the effect of a filter by increasing the value in the center cell
+ array( $level, $level, $level )
+ );
- }
+ }
## --------------------------------------------------------
- private function findSharp($orig, $final)
- # Author: Ryan Rud (http://adryrun.com)
- # Purpose: Find optimal sharpness
- # Param in: n/a
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- $final = $final * (750.0 / $orig);
- $a = 52;
- $b = -0.27810650887573124;
- $c = .00047337278106508946;
+ private function findSharp($orig, $final)
+ # Author: Ryan Rud (http://adryrun.com)
+ # Purpose: Find optimal sharpness
+ # Param in: n/a
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ $final = $final * (750.0 / $orig);
+ $a = 52;
+ $b = -0.27810650887573124;
+ $c = .00047337278106508946;
- $result = $a + $b * $final + $c * $final * $final;
+ $result = $a + $b * $final + $c * $final * $final;
- return max(round($result), 0);
- }
+ return max(round($result), 0);
+ }
## --------------------------------------------------------
- private function prepOption($option)
- # Author: Jarrod Oberto
- # Purpose: Prep option like change the passed in option to lowercase
- # Param in: (str/int) $option: eg. 'exact', 'crop'. 0, 4
- # Param out: lowercase string
- # Reference:
- # Notes:
- #
- {
- if (is_array($option))
- {
- if (fix_strtolower($option[0]) == 'crop' && count($option) == 2)
- {
- return 'crop';
- }
- else
- {
- throw new Exception('Crop resize option array is badly formatted.');
- }
- }
- else
- {
- if (strpos($option, 'crop') !== false)
- {
- return 'crop';
- }
- }
+ private function prepOption($option)
+ # Author: Jarrod Oberto
+ # Purpose: Prep option like change the passed in option to lowercase
+ # Param in: (str/int) $option: eg. 'exact', 'crop'. 0, 4
+ # Param out: lowercase string
+ # Reference:
+ # Notes:
+ #
+ {
+ if (is_array($option))
+ {
+ if (fix_strtolower($option[0]) == 'crop' && count($option) == 2)
+ {
+ return 'crop';
+ }
+ else
+ {
+ throw new Exception('Crop resize option array is badly formatted.');
+ }
+ }
+ else
+ {
+ if (strpos($option, 'crop') !== false)
+ {
+ return 'crop';
+ }
+ }
- if (is_string($option))
- {
- return fix_strtolower($option);
- }
+ if (is_string($option))
+ {
+ return fix_strtolower($option);
+ }
- return $option;
- }
+ return $option;
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Presets
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
@@ -981,2605 +980,2625 @@ class imageLib {
#
- public function borderPreset($preset)
- {
- switch ($preset)
- {
+ public function borderPreset($preset)
+ {
+ switch ($preset)
+ {
- case 'simple':
- $this->addBorder(7, '#fff');
- $this->addBorder(6, '#f2f1f0');
- $this->addBorder(2, '#fff');
- $this->addBorder(1, '#ccc');
- break;
- default:
- break;
- }
+ case 'simple':
+ $this->addBorder(7, '#fff');
+ $this->addBorder(6, '#f2f1f0');
+ $this->addBorder(2, '#fff');
+ $this->addBorder(1, '#ccc');
+ break;
+ default:
+ break;
+ }
- }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Draw border
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function addBorder($thickness = 1, $rgbArray = array( 255, 255, 255 ))
- # Author: Jarrod Oberto
- # Date: 05-05-11
- # Purpose: Add a border to the image
- # Param in:
- # Param out:
- # Reference:
- # Notes: This border is added to the INSIDE of the image
- #
- {
- if ($this->imageResized)
- {
+ public function addBorder($thickness = 1, $rgbArray = array( 255, 255, 255 ))
+ # Author: Jarrod Oberto
+ # Date: 05-05-11
+ # Purpose: Add a border to the image
+ # Param in:
+ # Param out:
+ # Reference:
+ # Notes: This border is added to the INSIDE of the image
+ #
+ {
+ if ($this->imageResized)
+ {
- $rgbArray = $this->formatColor($rgbArray);
- $r = $rgbArray['r'];
- $g = $rgbArray['g'];
- $b = $rgbArray['b'];
+ $rgbArray = $this->formatColor($rgbArray);
+ $r = $rgbArray['r'];
+ $g = $rgbArray['g'];
+ $b = $rgbArray['b'];
- $x1 = 0;
- $y1 = 0;
- $x2 = ImageSX($this->imageResized) - 1;
- $y2 = ImageSY($this->imageResized) - 1;
+ $x1 = 0;
+ $y1 = 0;
+ $x2 = ImageSX($this->imageResized) - 1;
+ $y2 = ImageSY($this->imageResized) - 1;
- $rgbArray = ImageColorAllocate($this->imageResized, $r, $g, $b);
+ $rgbArray = ImageColorAllocate($this->imageResized, $r, $g, $b);
- for ($i = 0; $i < $thickness; $i++)
- {
- ImageRectangle($this->imageResized, $x1++, $y1++, $x2--, $y2--, $rgbArray);
- }
- }
- }
+ for ($i = 0; $i < $thickness; $i++)
+ {
+ ImageRectangle($this->imageResized, $x1++, $y1++, $x2--, $y2--, $rgbArray);
+ }
+ }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Gray Scale
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function greyScale()
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Make image greyscale
- # Param in: n/a
- # Param out:
- # Reference:
- # Notes:
- #
- {
- if ($this->imageResized)
- {
- imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
- }
+ public function greyScale()
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Make image greyscale
+ # Param in: n/a
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ if ($this->imageResized)
+ {
+ imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
+ }
- }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- public function greyScaleEnhanced()
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Make image greyscale
- # Param in: n/a
- # Param out:
- # Reference:
- # Notes:
- #
- {
- if ($this->imageResized)
- {
- imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
- imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -15);
- imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, 2);
- $this->sharpen($this->width);
- }
- }
+ public function greyScaleEnhanced()
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Make image greyscale
+ # Param in: n/a
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ if ($this->imageResized)
+ {
+ imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
+ imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -15);
+ imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, 2);
+ $this->sharpen($this->width);
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- public function greyScaleDramatic()
- # Alias of gd_filter_monopin
- {
- $this->gd_filter_monopin();
- }
+ public function greyScaleDramatic()
+ # Alias of gd_filter_monopin
+ {
+ $this->gd_filter_monopin();
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Black 'n White
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function blackAndWhite()
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Make image black and white
- # Param in: n/a
- # Param out:
- # Reference:
- # Notes:
- #
- {
- if ($this->imageResized)
- {
+ public function blackAndWhite()
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Make image black and white
+ # Param in: n/a
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ if ($this->imageResized)
+ {
- imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
- imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -1000);
- }
+ imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
+ imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -1000);
+ }
- }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Negative
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function negative()
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Make image negative
- # Param in: n/a
- # Param out:
- # Reference:
- # Notes:
- #
- {
- if ($this->imageResized)
- {
+ public function negative()
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Make image negative
+ # Param in: n/a
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ if ($this->imageResized)
+ {
- imagefilter($this->imageResized, IMG_FILTER_NEGATE);
- }
+ imagefilter($this->imageResized, IMG_FILTER_NEGATE);
+ }
- }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Sepia
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function sepia()
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Make image sepia
- # Param in: n/a
- # Param out:
- # Reference:
- # Notes:
- #
- {
- if ($this->imageResized)
- {
- imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
- imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, -10);
- imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -20);
- imagefilter($this->imageResized, IMG_FILTER_COLORIZE, 60, 30, -15);
- }
- }
+ public function sepia()
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Make image sepia
+ # Param in: n/a
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ if ($this->imageResized)
+ {
+ imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
+ imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, -10);
+ imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -20);
+ imagefilter($this->imageResized, IMG_FILTER_COLORIZE, 60, 30, -15);
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- public function sepia2()
+ public function sepia2()
- {
- if ($this->imageResized)
- {
+ {
+ if ($this->imageResized)
+ {
- $total = imagecolorstotal($this->imageResized);
- for ($i = 0; $i < $total; $i++)
- {
- $index = imagecolorsforindex($this->imageResized, $i);
- $red = ($index["red"] * 0.393 + $index["green"] * 0.769 + $index["blue"] * 0.189) / 1.351;
- $green = ($index["red"] * 0.349 + $index["green"] * 0.686 + $index["blue"] * 0.168) / 1.203;
- $blue = ($index["red"] * 0.272 + $index["green"] * 0.534 + $index["blue"] * 0.131) / 2.140;
- imagecolorset($this->imageResized, $i, $red, $green, $blue);
- }
+ $total = imagecolorstotal($this->imageResized);
+ for ($i = 0; $i < $total; $i++)
+ {
+ $index = imagecolorsforindex($this->imageResized, $i);
+ $red = ($index["red"] * 0.393 + $index["green"] * 0.769 + $index["blue"] * 0.189) / 1.351;
+ $green = ($index["red"] * 0.349 + $index["green"] * 0.686 + $index["blue"] * 0.168) / 1.203;
+ $blue = ($index["red"] * 0.272 + $index["green"] * 0.534 + $index["blue"] * 0.131) / 2.140;
+ imagecolorset($this->imageResized, $i, $red, $green, $blue);
+ }
- }
- }
+ }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Vintage
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function vintage()
- # Alias of gd_filter_monopin
- {
- $this->gd_filter_vintage();
- }
+ public function vintage()
+ # Alias of gd_filter_monopin
+ {
+ $this->gd_filter_vintage();
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Presets By Marc Hibbins
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- /** Apply 'Monopin' preset */
- public function gd_filter_monopin()
- {
+ /** Apply 'Monopin' preset */
+ public function gd_filter_monopin()
+ {
- if ($this->imageResized)
- {
- imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
- imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, -15);
- imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -15);
- $this->imageResized = $this->gd_apply_overlay($this->imageResized, 'vignette', 100);
- }
- }
+ if ($this->imageResized)
+ {
+ imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
+ imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, -15);
+ imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -15);
+ $this->imageResized = $this->gd_apply_overlay($this->imageResized, 'vignette', 100);
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- public function gd_filter_vintage()
- {
- if ($this->imageResized)
- {
- $this->imageResized = $this->gd_apply_overlay($this->imageResized, 'vignette', 45);
- imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, 20);
- imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -35);
- imagefilter($this->imageResized, IMG_FILTER_COLORIZE, 60, -10, 35);
- imagefilter($this->imageResized, IMG_FILTER_SMOOTH, 7);
- $this->imageResized = $this->gd_apply_overlay($this->imageResized, 'scratch', 10);
- }
- }
+ public function gd_filter_vintage()
+ {
+ if ($this->imageResized)
+ {
+ $this->imageResized = $this->gd_apply_overlay($this->imageResized, 'vignette', 45);
+ imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, 20);
+ imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -35);
+ imagefilter($this->imageResized, IMG_FILTER_COLORIZE, 60, -10, 35);
+ imagefilter($this->imageResized, IMG_FILTER_SMOOTH, 7);
+ $this->imageResized = $this->gd_apply_overlay($this->imageResized, 'scratch', 10);
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- /** Apply a PNG overlay */
- private function gd_apply_overlay($im, $type, $amount)
- #
- # Original Author: Marc Hibbins
- # License: Attribution-ShareAlike 3.0
- # Purpose:
- # Params in:
- # Params out:
- # Notes:
- #
- {
- $width = imagesx($im);
- $height = imagesy($im);
- $filter = imagecreatetruecolor($width, $height);
+ /** Apply a PNG overlay */
+ private function gd_apply_overlay($im, $type, $amount)
+ #
+ # Original Author: Marc Hibbins
+ # License: Attribution-ShareAlike 3.0
+ # Purpose:
+ # Params in:
+ # Params out:
+ # Notes:
+ #
+ {
+ $width = imagesx($im);
+ $height = imagesy($im);
+ $filter = imagecreatetruecolor($width, $height);
- imagealphablending($filter, false);
- imagesavealpha($filter, true);
+ imagealphablending($filter, false);
+ imagesavealpha($filter, true);
- $transparent = imagecolorallocatealpha($filter, 255, 255, 255, 127);
- imagefilledrectangle($filter, 0, 0, $width, $height, $transparent);
+ $transparent = imagecolorallocatealpha($filter, 255, 255, 255, 127);
+ imagefilledrectangle($filter, 0, 0, $width, $height, $transparent);
- // *** Resize overlay
- $overlay = $this->filterOverlayPath . '/' . $type . '.png';
- $png = imagecreatefrompng($overlay);
- imagecopyresampled($filter, $png, 0, 0, 0, 0, $width, $height, imagesx($png), imagesy($png));
+ // *** Resize overlay
+ $overlay = $this->filterOverlayPath . '/' . $type . '.png';
+ $png = imagecreatefrompng($overlay);
+ imagecopyresampled($filter, $png, 0, 0, 0, 0, $width, $height, imagesx($png), imagesy($png));
- $comp = imagecreatetruecolor($width, $height);
- imagecopy($comp, $im, 0, 0, 0, 0, $width, $height);
- imagecopy($comp, $filter, 0, 0, 0, 0, $width, $height);
- imagecopymerge($im, $comp, 0, 0, 0, 0, $width, $height, $amount);
+ $comp = imagecreatetruecolor($width, $height);
+ imagecopy($comp, $im, 0, 0, 0, 0, $width, $height);
+ imagecopy($comp, $filter, 0, 0, 0, 0, $width, $height);
+ imagecopymerge($im, $comp, 0, 0, 0, 0, $width, $height, $amount);
- imagedestroy($comp);
+ imagedestroy($comp);
- return $im;
- }
+ return $im;
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Colorise
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function image_colorize($rgb)
- {
- imageTrueColorToPalette($this->imageResized, true, 256);
- $numColors = imageColorsTotal($this->imageResized);
+ public function image_colorize($rgb)
+ {
+ imageTrueColorToPalette($this->imageResized, true, 256);
+ $numColors = imageColorsTotal($this->imageResized);
- for ($x = 0; $x < $numColors; $x++)
- {
- list($r, $g, $b) = array_values(imageColorsForIndex($this->imageResized, $x));
+ for ($x = 0; $x < $numColors; $x++)
+ {
+ list($r, $g, $b) = array_values(imageColorsForIndex($this->imageResized, $x));
- // calculate grayscale in percent
- $grayscale = ($r + $g + $b) / 3 / 0xff;
+ // calculate grayscale in percent
+ $grayscale = ($r + $g + $b) / 3 / 0xff;
- imageColorSet($this->imageResized, $x,
- $grayscale * $rgb[0],
- $grayscale * $rgb[1],
- $grayscale * $rgb[2]
- );
+ imageColorSet($this->imageResized, $x,
+ $grayscale * $rgb[0],
+ $grayscale * $rgb[1],
+ $grayscale * $rgb[2]
+ );
- }
+ }
- return true;
- }
+ return true;
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Reflection
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function addReflection($reflectionHeight = 50, $startingTransparency = 30, $inside = false, $bgColor = '#fff', $stretch = false, $divider = 0)
- {
+ public function addReflection($reflectionHeight = 50, $startingTransparency = 30, $inside = false, $bgColor = '#fff', $stretch = false, $divider = 0)
+ {
- // *** Convert color
- $rgbArray = $this->formatColor($bgColor);
- $r = $rgbArray['r'];
- $g = $rgbArray['g'];
- $b = $rgbArray['b'];
+ // *** Convert color
+ $rgbArray = $this->formatColor($bgColor);
+ $r = $rgbArray['r'];
+ $g = $rgbArray['g'];
+ $b = $rgbArray['b'];
- $im = $this->imageResized;
- $li = imagecreatetruecolor($this->width, 1);
+ $im = $this->imageResized;
+ $li = imagecreatetruecolor($this->width, 1);
- $bgc = imagecolorallocate($li, $r, $g, $b);
- imagefilledrectangle($li, 0, 0, $this->width, 1, $bgc);
+ $bgc = imagecolorallocate($li, $r, $g, $b);
+ imagefilledrectangle($li, 0, 0, $this->width, 1, $bgc);
- $bg = imagecreatetruecolor($this->width, $reflectionHeight);
- $wh = imagecolorallocate($im, 255, 255, 255);
+ $bg = imagecreatetruecolor($this->width, $reflectionHeight);
+ $wh = imagecolorallocate($im, 255, 255, 255);
- $im = imagerotate($im, -180, $wh);
- imagecopyresampled($bg, $im, 0, 0, 0, 0, $this->width, $this->height, $this->width, $this->height);
+ $im = imagerotate($im, -180, $wh);
+ imagecopyresampled($bg, $im, 0, 0, 0, 0, $this->width, $this->height, $this->width, $this->height);
- $im = $bg;
+ $im = $bg;
- $bg = imagecreatetruecolor($this->width, $reflectionHeight);
+ $bg = imagecreatetruecolor($this->width, $reflectionHeight);
- for ($x = 0; $x < $this->width; $x++)
- {
- imagecopy($bg, $im, $x, 0, $this->width - $x - 1, 0, 1, $reflectionHeight);
- }
- $im = $bg;
+ for ($x = 0; $x < $this->width; $x++)
+ {
+ imagecopy($bg, $im, $x, 0, $this->width - $x - 1, 0, 1, $reflectionHeight);
+ }
+ $im = $bg;
- $transaprencyAmount = $this->invertTransparency($startingTransparency, 100);
+ $transaprencyAmount = $this->invertTransparency($startingTransparency, 100);
- // *** Fade
- if ($stretch)
- {
- $step = 100 / ($reflectionHeight + $startingTransparency);
- }
- else
- {
- $step = 100 / $reflectionHeight;
- }
- for ($i = 0; $i <= $reflectionHeight; $i++)
- {
+ // *** Fade
+ if ($stretch)
+ {
+ $step = 100 / ($reflectionHeight + $startingTransparency);
+ }
+ else
+ {
+ $step = 100 / $reflectionHeight;
+ }
+ for ($i = 0; $i <= $reflectionHeight; $i++)
+ {
- if ($startingTransparency > 100)
- {
- $startingTransparency = 100;
- }
- if ($startingTransparency < 1)
- {
- $startingTransparency = 1;
- }
- imagecopymerge($bg, $li, 0, $i, 0, 0, $this->width, 1, $startingTransparency);
- $startingTransparency += $step;
- }
+ if ($startingTransparency > 100)
+ {
+ $startingTransparency = 100;
+ }
+ if ($startingTransparency < 1)
+ {
+ $startingTransparency = 1;
+ }
+ imagecopymerge($bg, $li, 0, $i, 0, 0, $this->width, 1, $startingTransparency);
+ $startingTransparency += $step;
+ }
- // *** Apply fade
- imagecopymerge($im, $li, 0, 0, 0, 0, $this->width, $divider, 100); // Divider
+ // *** Apply fade
+ imagecopymerge($im, $li, 0, 0, 0, 0, $this->width, $divider, 100); // Divider
- // *** width, height of reflection.
- $x = imagesx($im);
- $y = imagesy($im);
+ // *** width, height of reflection.
+ $x = imagesx($im);
+ $y = imagesy($im);
- // *** Determines if the reflection should be displayed inside or outside the image
- if ($inside)
- {
+ // *** Determines if the reflection should be displayed inside or outside the image
+ if ($inside)
+ {
- // Create new blank image with sizes.
- $final = imagecreatetruecolor($this->width, $this->height);
+ // Create new blank image with sizes.
+ $final = imagecreatetruecolor($this->width, $this->height);
- imagecopymerge($final, $this->imageResized, 0, 0, 0, $reflectionHeight, $this->width, $this->height - $reflectionHeight, 100);
- imagecopymerge($final, $im, 0, $this->height - $reflectionHeight, 0, 0, $x, $y, 100);
+ imagecopymerge($final, $this->imageResized, 0, 0, 0, $reflectionHeight, $this->width, $this->height - $reflectionHeight, 100);
+ imagecopymerge($final, $im, 0, $this->height - $reflectionHeight, 0, 0, $x, $y, 100);
- }
- else
- {
+ }
+ else
+ {
- // Create new blank image with sizes.
- $final = imagecreatetruecolor($this->width, $this->height + $y);
+ // Create new blank image with sizes.
+ $final = imagecreatetruecolor($this->width, $this->height + $y);
- imagecopymerge($final, $this->imageResized, 0, 0, 0, 0, $this->width, $this->height, 100);
- imagecopymerge($final, $im, 0, $this->height, 0, 0, $x, $y, 100);
- }
+ imagecopymerge($final, $this->imageResized, 0, 0, 0, 0, $this->width, $this->height, 100);
+ imagecopymerge($final, $im, 0, $this->height, 0, 0, $x, $y, 100);
+ }
- $this->imageResized = $final;
+ $this->imageResized = $final;
- imagedestroy($li);
- imagedestroy($im);
- }
+ imagedestroy($li);
+ imagedestroy($im);
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Rotate
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function rotate($value = 90, $bgColor = 'transparent')
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Rotate image
- # Param in: (mixed) $degrees: (int) number of degress to rotate image
- # (str) param "left": rotate left
- # (str) param "right": rotate right
- # (str) param "upside": upside-down image
- # Param out:
- # Reference:
- # Notes: The default direction of imageRotate() is counter clockwise.
- #
- {
- if ($this->imageResized)
- {
+ public function rotate($value = 90, $bgColor = 'transparent')
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Rotate image
+ # Param in: (mixed) $degrees: (int) number of degress to rotate image
+ # (str) param "left": rotate left
+ # (str) param "right": rotate right
+ # (str) param "upside": upside-down image
+ # Param out:
+ # Reference:
+ # Notes: The default direction of imageRotate() is counter clockwise.
+ #
+ {
+ if ($this->imageResized)
+ {
- if (is_integer($value))
- {
- $degrees = $value;
- }
+ if (is_integer($value))
+ {
+ $degrees = $value;
+ }
- // *** Convert color
- $rgbArray = $this->formatColor($bgColor);
- $r = $rgbArray['r'];
- $g = $rgbArray['g'];
- $b = $rgbArray['b'];
- if (isset($rgbArray['a']))
- {
- $a = $rgbArray['a'];
- }
+ // *** Convert color
+ $rgbArray = $this->formatColor($bgColor);
+ $r = $rgbArray['r'];
+ $g = $rgbArray['g'];
+ $b = $rgbArray['b'];
+ if (isset($rgbArray['a']))
+ {
+ $a = $rgbArray['a'];
+ }
- if (is_string($value))
- {
+ if (is_string($value))
+ {
- $value = fix_strtolower($value);
+ $value = fix_strtolower($value);
- switch ($value)
- {
- case 'left':
- $degrees = 90;
- break;
- case 'right':
- $degrees = 270;
- break;
- case 'upside':
- $degrees = 180;
- break;
- default:
- break;
- }
+ switch ($value)
+ {
+ case 'left':
+ $degrees = 90;
+ break;
+ case 'right':
+ $degrees = 270;
+ break;
+ case 'upside':
+ $degrees = 180;
+ break;
+ default:
+ break;
+ }
- }
+ }
- // *** The default direction of imageRotate() is counter clockwise
- // * This makes it clockwise
- $degrees = 360 - $degrees;
+ // *** The default direction of imageRotate() is counter clockwise
+ // * This makes it clockwise
+ $degrees = 360 - $degrees;
- // *** Create background color
- $bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a);
+ // *** Create background color
+ $bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a);
- // *** Fill with background
- ImageFill($this->imageResized, 0, 0, $bg);
+ // *** Fill with background
+ ImageFill($this->imageResized, 0, 0, $bg);
- // *** Rotate
- $this->imageResized = imagerotate($this->imageResized, $degrees, $bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)
+ // *** Rotate
+ $this->imageResized = imagerotate($this->imageResized, $degrees, $bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)
- // Ensure alpha transparency
- ImageSaveAlpha($this->imageResized, true);
+ // Ensure alpha transparency
+ ImageSaveAlpha($this->imageResized, true);
- }
- }
+ }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Round corners
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function roundCorners($radius = 5, $bgColor = 'transparent')
- # Author: Jarrod Oberto
- # Date: 19-05-2011
- # Purpose: Create rounded corners on your image
- # Param in: (int) radius = the amount of curvature
- # (mixed) $bgColor = the corner background color
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
+ public function roundCorners($radius = 5, $bgColor = 'transparent')
+ # Author: Jarrod Oberto
+ # Date: 19-05-2011
+ # Purpose: Create rounded corners on your image
+ # Param in: (int) radius = the amount of curvature
+ # (mixed) $bgColor = the corner background color
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
- // *** Check if the user wants transparency
- $isTransparent = false;
- if ( ! is_array($bgColor))
- {
- if (fix_strtolower($bgColor) == 'transparent')
- {
- $isTransparent = true;
- }
- }
+ // *** Check if the user wants transparency
+ $isTransparent = false;
+ if ( ! is_array($bgColor))
+ {
+ if (fix_strtolower($bgColor) == 'transparent')
+ {
+ $isTransparent = true;
+ }
+ }
- // *** If we use transparency, we need to color our curved mask with a unique color
- if ($isTransparent)
- {
- $bgColor = $this->findUnusedGreen();
- }
+ // *** If we use transparency, we need to color our curved mask with a unique color
+ if ($isTransparent)
+ {
+ $bgColor = $this->findUnusedGreen();
+ }
- // *** Convert color
- $rgbArray = $this->formatColor($bgColor);
- $r = $rgbArray['r'];
- $g = $rgbArray['g'];
- $b = $rgbArray['b'];
- if (isset($rgbArray['a']))
- {
- $a = $rgbArray['a'];
- }
+ // *** Convert color
+ $rgbArray = $this->formatColor($bgColor);
+ $r = $rgbArray['r'];
+ $g = $rgbArray['g'];
+ $b = $rgbArray['b'];
+ if (isset($rgbArray['a']))
+ {
+ $a = $rgbArray['a'];
+ }
- // *** Create top-left corner mask (square)
- $cornerImg = imagecreatetruecolor($radius, $radius);
- //$cornerImg = imagecreate($radius, $radius);
+ // *** Create top-left corner mask (square)
+ $cornerImg = imagecreatetruecolor($radius, $radius);
+ //$cornerImg = imagecreate($radius, $radius);
- //imagealphablending($cornerImg, true);
- //imagesavealpha($cornerImg, true);
+ //imagealphablending($cornerImg, true);
+ //imagesavealpha($cornerImg, true);
- //imagealphablending($this->imageResized, false);
- //imagesavealpha($this->imageResized, true);
+ //imagealphablending($this->imageResized, false);
+ //imagesavealpha($this->imageResized, true);
- // *** Give it a color
- $maskColor = imagecolorallocate($cornerImg, 0, 0, 0);
+ // *** Give it a color
+ $maskColor = imagecolorallocate($cornerImg, 0, 0, 0);
- // *** Replace the mask color (black) to transparent
- imagecolortransparent($cornerImg, $maskColor);
+ // *** Replace the mask color (black) to transparent
+ imagecolortransparent($cornerImg, $maskColor);
- // *** Create the image background color
- $imagebgColor = imagecolorallocate($cornerImg, $r, $g, $b);
+ // *** Create the image background color
+ $imagebgColor = imagecolorallocate($cornerImg, $r, $g, $b);
- // *** Fill the corner area to the user defined color
- imagefill($cornerImg, 0, 0, $imagebgColor);
+ // *** Fill the corner area to the user defined color
+ imagefill($cornerImg, 0, 0, $imagebgColor);
- imagefilledellipse($cornerImg, $radius, $radius, $radius * 2, $radius * 2, $maskColor);
+ imagefilledellipse($cornerImg, $radius, $radius, $radius * 2, $radius * 2, $maskColor);
- // *** Map to top left corner
- imagecopymerge($this->imageResized, $cornerImg, 0, 0, 0, 0, $radius, $radius, 100); #tl
+ // *** Map to top left corner
+ imagecopymerge($this->imageResized, $cornerImg, 0, 0, 0, 0, $radius, $radius, 100); #tl
- // *** Map rounded corner to other corners by rotating and applying the mask
- $cornerImg = imagerotate($cornerImg, 90, 0);
- imagecopymerge($this->imageResized, $cornerImg, 0, $this->height - $radius, 0, 0, $radius, $radius, 100); #bl
+ // *** Map rounded corner to other corners by rotating and applying the mask
+ $cornerImg = imagerotate($cornerImg, 90, 0);
+ imagecopymerge($this->imageResized, $cornerImg, 0, $this->height - $radius, 0, 0, $radius, $radius, 100); #bl
- $cornerImg = imagerotate($cornerImg, 90, 0);
- imagecopymerge($this->imageResized, $cornerImg, $this->width - $radius, $this->height - $radius, 0, 0, $radius, $radius, 100); #br
+ $cornerImg = imagerotate($cornerImg, 90, 0);
+ imagecopymerge($this->imageResized, $cornerImg, $this->width - $radius, $this->height - $radius, 0, 0, $radius, $radius, 100); #br
- $cornerImg = imagerotate($cornerImg, 90, 0);
- imagecopymerge($this->imageResized, $cornerImg, $this->width - $radius, 0, 0, 0, $radius, $radius, 100); #tr
+ $cornerImg = imagerotate($cornerImg, 90, 0);
+ imagecopymerge($this->imageResized, $cornerImg, $this->width - $radius, 0, 0, 0, $radius, $radius, 100); #tr
- // *** If corners are to be transparent, we fill our chromakey color as transparent.
- if ($isTransparent)
- {
- //imagecolortransparent($this->imageResized, $imagebgColor);
- $this->imageResized = $this->transparentImage($this->imageResized);
- imagesavealpha($this->imageResized, true);
- }
+ // *** If corners are to be transparent, we fill our chromakey color as transparent.
+ if ($isTransparent)
+ {
+ //imagecolortransparent($this->imageResized, $imagebgColor);
+ $this->imageResized = $this->transparentImage($this->imageResized);
+ imagesavealpha($this->imageResized, true);
+ }
- }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Shadow
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent')
- #
- # Author: Jarrod Oberto (Adapted from Pascal Naidon)
- # Ref: http://www.les-stooges.org/pascal/webdesign/vignettes/index.php?la=en
- # Purpose: Add a drop shadow to your image
- # Params in: (int) $angle: the angle of the shadow
- # (int) $blur: the blur distance
- # (mixed) $bgColor: the color of the background
- # Params out:
- # Notes:
- #
- {
- // *** A higher number results in a smoother shadow
- define('STEPS', $blur * 2);
+ public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent')
+ #
+ # Author: Jarrod Oberto (Adapted from Pascal Naidon)
+ # Ref: http://www.les-stooges.org/pascal/webdesign/vignettes/index.php?la=en
+ # Purpose: Add a drop shadow to your image
+ # Params in: (int) $angle: the angle of the shadow
+ # (int) $blur: the blur distance
+ # (mixed) $bgColor: the color of the background
+ # Params out:
+ # Notes:
+ #
+ {
+ // *** A higher number results in a smoother shadow
+ define('STEPS', $blur * 2);
- // *** Set the shadow distance
- $shadowDistance = $blur * 0.25;
+ // *** Set the shadow distance
+ $shadowDistance = $blur * 0.25;
- // *** Set blur width and height
- $blurWidth = $blurHeight = $blur;
+ // *** Set blur width and height
+ $blurWidth = $blurHeight = $blur;
- if ($shadowAngle == 0)
- {
- $distWidth = 0;
- $distHeight = 0;
- }
- else
- {
- $distWidth = $shadowDistance * cos(deg2rad($shadowAngle));
- $distHeight = $shadowDistance * sin(deg2rad($shadowAngle));
- }
+ if ($shadowAngle == 0)
+ {
+ $distWidth = 0;
+ $distHeight = 0;
+ }
+ else
+ {
+ $distWidth = $shadowDistance * cos(deg2rad($shadowAngle));
+ $distHeight = $shadowDistance * sin(deg2rad($shadowAngle));
+ }
- // *** Convert color
- if (fix_strtolower($bgColor) != 'transparent')
- {
- $rgbArray = $this->formatColor($bgColor);
- $r0 = $rgbArray['r'];
- $g0 = $rgbArray['g'];
- $b0 = $rgbArray['b'];
- }
+ // *** Convert color
+ if (fix_strtolower($bgColor) != 'transparent')
+ {
+ $rgbArray = $this->formatColor($bgColor);
+ $r0 = $rgbArray['r'];
+ $g0 = $rgbArray['g'];
+ $b0 = $rgbArray['b'];
+ }
- $image = $this->imageResized;
- $width = $this->width;
- $height = $this->height;
+ $image = $this->imageResized;
+ $width = $this->width;
+ $height = $this->height;
- $newImage = imagecreatetruecolor($width, $height);
- imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $width, $height);
+ $newImage = imagecreatetruecolor($width, $height);
+ imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $width, $height);
- // *** RGB
- $rgb = imagecreatetruecolor($width + $blurWidth, $height + $blurHeight);
- $colour = imagecolorallocate($rgb, 0, 0, 0);
- imagefilledrectangle($rgb, 0, 0, $width + $blurWidth, $height + $blurHeight, $colour);
- $colour = imagecolorallocate($rgb, 255, 255, 255);
- //imagefilledrectangle($rgb, $blurWidth*0.5-$distWidth, $blurHeight*0.5-$distHeight, $width+$blurWidth*0.5-$distWidth, $height+$blurWidth*0.5-$distHeight, $colour);
- imagefilledrectangle($rgb, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - $distWidth, $height + $blurWidth * 0.5 - $distHeight, $colour);
- //imagecopymerge($rgb, $newImage, 1+$blurWidth*0.5-$distWidth, 1+$blurHeight*0.5-$distHeight, 0,0, $width, $height, 100);
- imagecopymerge($rgb, $newImage, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, 0, 0, $width + $blurWidth, $height + $blurHeight, 100);
+ // *** RGB
+ $rgb = imagecreatetruecolor($width + $blurWidth, $height + $blurHeight);
+ $colour = imagecolorallocate($rgb, 0, 0, 0);
+ imagefilledrectangle($rgb, 0, 0, $width + $blurWidth, $height + $blurHeight, $colour);
+ $colour = imagecolorallocate($rgb, 255, 255, 255);
+ //imagefilledrectangle($rgb, $blurWidth*0.5-$distWidth, $blurHeight*0.5-$distHeight, $width+$blurWidth*0.5-$distWidth, $height+$blurWidth*0.5-$distHeight, $colour);
+ imagefilledrectangle($rgb, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - $distWidth, $height + $blurWidth * 0.5 - $distHeight, $colour);
+ //imagecopymerge($rgb, $newImage, 1+$blurWidth*0.5-$distWidth, 1+$blurHeight*0.5-$distHeight, 0,0, $width, $height, 100);
+ imagecopymerge($rgb, $newImage, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, 0, 0, $width + $blurWidth, $height + $blurHeight, 100);
- // *** Shadow (alpha)
- $shadow = imagecreatetruecolor($width + $blurWidth, $height + $blurHeight);
- imagealphablending($shadow, false);
- $colour = imagecolorallocate($shadow, 0, 0, 0);
- imagefilledrectangle($shadow, 0, 0, $width + $blurWidth, $height + $blurHeight, $colour);
+ // *** Shadow (alpha)
+ $shadow = imagecreatetruecolor($width + $blurWidth, $height + $blurHeight);
+ imagealphablending($shadow, false);
+ $colour = imagecolorallocate($shadow, 0, 0, 0);
+ imagefilledrectangle($shadow, 0, 0, $width + $blurWidth, $height + $blurHeight, $colour);
- for ($i = 0; $i <= STEPS; $i++)
- {
+ for ($i = 0; $i <= STEPS; $i++)
+ {
- $t = ((1.0 * $i) / STEPS);
- $intensity = 255 * $t * $t;
+ $t = ((1.0 * $i) / STEPS);
+ $intensity = 255 * $t * $t;
- $colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);
- $points = array(
- $blurWidth * $t, $blurHeight, // Point 1 (x, y)
- $blurWidth, $blurHeight * $t, // Point 2 (x, y)
- $width, $blurHeight * $t, // Point 3 (x, y)
- $width + $blurWidth * (1 - $t), $blurHeight, // Point 4 (x, y)
- $width + $blurWidth * (1 - $t), $height, // Point 5 (x, y)
- $width, $height + $blurHeight * (1 - $t), // Point 6 (x, y)
- $blurWidth, $height + $blurHeight * (1 - $t), // Point 7 (x, y)
- $blurWidth * $t, $height // Point 8 (x, y)
- );
- imagepolygon($shadow, $points, 8, $colour);
- }
+ $colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);
+ $points = array(
+ $blurWidth * $t, $blurHeight, // Point 1 (x, y)
+ $blurWidth, $blurHeight * $t, // Point 2 (x, y)
+ $width, $blurHeight * $t, // Point 3 (x, y)
+ $width + $blurWidth * (1 - $t), $blurHeight, // Point 4 (x, y)
+ $width + $blurWidth * (1 - $t), $height, // Point 5 (x, y)
+ $width, $height + $blurHeight * (1 - $t), // Point 6 (x, y)
+ $blurWidth, $height + $blurHeight * (1 - $t), // Point 7 (x, y)
+ $blurWidth * $t, $height // Point 8 (x, y)
+ );
+ imagepolygon($shadow, $points, 8, $colour);
+ }
- for ($i = 0; $i <= STEPS; $i++)
- {
+ for ($i = 0; $i <= STEPS; $i++)
+ {
- $t = ((1.0 * $i) / STEPS);
- $intensity = 255 * $t * $t;
+ $t = ((1.0 * $i) / STEPS);
+ $intensity = 255 * $t * $t;
- $colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);
- imagefilledarc($shadow, $blurWidth - 1, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 180, 268, $colour, IMG_ARC_PIE);
- imagefilledarc($shadow, $width, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 270, 358, $colour, IMG_ARC_PIE);
- imagefilledarc($shadow, $width, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 0, 90, $colour, IMG_ARC_PIE);
- imagefilledarc($shadow, $blurWidth - 1, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 90, 180, $colour, IMG_ARC_PIE);
- }
+ $colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);
+ imagefilledarc($shadow, $blurWidth - 1, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 180, 268, $colour, IMG_ARC_PIE);
+ imagefilledarc($shadow, $width, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 270, 358, $colour, IMG_ARC_PIE);
+ imagefilledarc($shadow, $width, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 0, 90, $colour, IMG_ARC_PIE);
+ imagefilledarc($shadow, $blurWidth - 1, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 90, 180, $colour, IMG_ARC_PIE);
+ }
- $colour = imagecolorallocate($shadow, 255, 255, 255);
- imagefilledrectangle($shadow, $blurWidth, $blurHeight, $width, $height, $colour);
- imagefilledrectangle($shadow, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - 1 - $distWidth, $height + $blurHeight * 0.5 - 1 - $distHeight, $colour);
+ $colour = imagecolorallocate($shadow, 255, 255, 255);
+ imagefilledrectangle($shadow, $blurWidth, $blurHeight, $width, $height, $colour);
+ imagefilledrectangle($shadow, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - 1 - $distWidth, $height + $blurHeight * 0.5 - 1 - $distHeight, $colour);
- // *** The magic
- imagealphablending($rgb, false);
+ // *** The magic
+ imagealphablending($rgb, false);
- for ($theX = 0; $theX < imagesx($rgb); $theX++)
- {
- for ($theY = 0; $theY < imagesy($rgb); $theY++)
- {
+ for ($theX = 0; $theX < imagesx($rgb); $theX++)
+ {
+ for ($theY = 0; $theY < imagesy($rgb); $theY++)
+ {
- // *** Get the RGB values for every pixel of the RGB image
- $colArray = imagecolorat($rgb, $theX, $theY);
- $r = ($colArray >> 16) & 0xFF;
- $g = ($colArray >> 8) & 0xFF;
- $b = $colArray & 0xFF;
+ // *** Get the RGB values for every pixel of the RGB image
+ $colArray = imagecolorat($rgb, $theX, $theY);
+ $r = ($colArray >> 16) & 0xFF;
+ $g = ($colArray >> 8) & 0xFF;
+ $b = $colArray & 0xFF;
- // *** Get the alpha value for every pixel of the shadow image
- $colArray = imagecolorat($shadow, $theX, $theY);
- $a = $colArray & 0xFF;
- $a = 127 - floor($a / 2);
- $t = $a / 128.0;
+ // *** Get the alpha value for every pixel of the shadow image
+ $colArray = imagecolorat($shadow, $theX, $theY);
+ $a = $colArray & 0xFF;
+ $a = 127 - floor($a / 2);
+ $t = $a / 128.0;
- // *** Create color
- if (fix_strtolower($bgColor) == 'transparent')
- {
- $myColour = imagecolorallocatealpha($rgb, $r, $g, $b, $a);
- }
- else
- {
- $myColour = imagecolorallocate($rgb, $r * (1.0 - $t) + $r0 * $t, $g * (1.0 - $t) + $g0 * $t, $b * (1.0 - $t) + $b0 * $t);
- }
+ // *** Create color
+ if (fix_strtolower($bgColor) == 'transparent')
+ {
+ $myColour = imagecolorallocatealpha($rgb, $r, $g, $b, $a);
+ }
+ else
+ {
+ $myColour = imagecolorallocate($rgb, $r * (1.0 - $t) + $r0 * $t, $g * (1.0 - $t) + $g0 * $t, $b * (1.0 - $t) + $b0 * $t);
+ }
- // *** Add color to new rgb image
- imagesetpixel($rgb, $theX, $theY, $myColour);
- }
- }
+ // *** Add color to new rgb image
+ imagesetpixel($rgb, $theX, $theY, $myColour);
+ }
+ }
- imagealphablending($rgb, true);
- imagesavealpha($rgb, true);
+ imagealphablending($rgb, true);
+ imagesavealpha($rgb, true);
- $this->imageResized = $rgb;
+ $this->imageResized = $rgb;
- imagedestroy($image);
- imagedestroy($newImage);
- imagedestroy($shadow);
- }
+ imagedestroy($image);
+ imagedestroy($newImage);
+ imagedestroy($shadow);
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Add Caption Box
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function addCaptionBox($side = 'b', $thickness = 50, $padding = 0, $bgColor = '#000', $transaprencyAmount = 30)
- #
- # Author: Jarrod Oberto
- # Date: 26 May 2011
- # Purpose: Add a caption box
- # Params in: (str) $side: the side to add the caption box (t, r, b, or l).
- # (int) $thickness: how thick you want the caption box to be.
- # (mixed) $bgColor: The color of the caption box.
- # (int) $transaprencyAmount: The amount of transparency to be
- # applied.
- # Params out: n/a
- # Notes:
- #
- {
- $side = fix_strtolower($side);
+ public function addCaptionBox($side = 'b', $thickness = 50, $padding = 0, $bgColor = '#000', $transaprencyAmount = 30)
+ #
+ # Author: Jarrod Oberto
+ # Date: 26 May 2011
+ # Purpose: Add a caption box
+ # Params in: (str) $side: the side to add the caption box (t, r, b, or l).
+ # (int) $thickness: how thick you want the caption box to be.
+ # (mixed) $bgColor: The color of the caption box.
+ # (int) $transaprencyAmount: The amount of transparency to be
+ # applied.
+ # Params out: n/a
+ # Notes:
+ #
+ {
+ $side = fix_strtolower($side);
- // *** Convert color
- $rgbArray = $this->formatColor($bgColor);
- $r = $rgbArray['r'];
- $g = $rgbArray['g'];
- $b = $rgbArray['b'];
+ // *** Convert color
+ $rgbArray = $this->formatColor($bgColor);
+ $r = $rgbArray['r'];
+ $g = $rgbArray['g'];
+ $b = $rgbArray['b'];
- $positionArray = $this->calculateCaptionBoxPosition($side, $thickness, $padding);
+ $positionArray = $this->calculateCaptionBoxPosition($side, $thickness, $padding);
- // *** Store incase we want to use method addTextToCaptionBox()
- $this->captionBoxPositionArray = $positionArray;
+ // *** Store incase we want to use method addTextToCaptionBox()
+ $this->captionBoxPositionArray = $positionArray;
- $transaprencyAmount = $this->invertTransparency($transaprencyAmount, 127, false);
- $transparent = imagecolorallocatealpha($this->imageResized, $r, $g, $b, $transaprencyAmount);
- imagefilledrectangle($this->imageResized, $positionArray['x1'], $positionArray['y1'], $positionArray['x2'], $positionArray['y2'], $transparent);
- }
+ $transaprencyAmount = $this->invertTransparency($transaprencyAmount, 127, false);
+ $transparent = imagecolorallocatealpha($this->imageResized, $r, $g, $b, $transaprencyAmount);
+ imagefilledrectangle($this->imageResized, $positionArray['x1'], $positionArray['y1'], $positionArray['x2'], $positionArray['y2'], $transparent);
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- public function addTextToCaptionBox($text, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
- #
- # Author: Jarrod Oberto
- # Date: 03 Aug 11
- # Purpose: Simplify adding text to a caption box by automatically
- # locating the center of the caption box
- # Params in: The usually text paams (less a couple)
- # Params out: n/a
- # Notes:
- #
- {
+ public function addTextToCaptionBox($text, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
+ #
+ # Author: Jarrod Oberto
+ # Date: 03 Aug 11
+ # Purpose: Simplify adding text to a caption box by automatically
+ # locating the center of the caption box
+ # Params in: The usually text paams (less a couple)
+ # Params out: n/a
+ # Notes:
+ #
+ {
- // *** Get the caption box measurements
- if (count($this->captionBoxPositionArray) == 4)
- {
- $x1 = $this->captionBoxPositionArray['x1'];
- $x2 = $this->captionBoxPositionArray['x2'];
- $y1 = $this->captionBoxPositionArray['y1'];
- $y2 = $this->captionBoxPositionArray['y2'];
- }
- else
- {
- if ($this->debug)
- {
- throw new Exception('No caption box found.');
- }
- else
- {
- return false;
- }
- }
+ // *** Get the caption box measurements
+ if (count($this->captionBoxPositionArray) == 4)
+ {
+ $x1 = $this->captionBoxPositionArray['x1'];
+ $x2 = $this->captionBoxPositionArray['x2'];
+ $y1 = $this->captionBoxPositionArray['y1'];
+ $y2 = $this->captionBoxPositionArray['y2'];
+ }
+ else
+ {
+ if ($this->debug)
+ {
+ throw new Exception('No caption box found.');
+ }
+ else
+ {
+ return false;
+ }
+ }
- // *** Get text font
- $font = $this->getTextFont($font);
+ // *** Get text font
+ $font = $this->getTextFont($font);
- // *** Get text size
- $textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
- $textWidth = $textSizeArray['width'];
- $textHeight = $textSizeArray['height'];
+ // *** Get text size
+ $textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
+ $textWidth = $textSizeArray['width'];
+ $textHeight = $textSizeArray['height'];
- // *** Find the width/height middle points
- $boxXMiddle = (($x2 - $x1) / 2);
- $boxYMiddle = (($y2 - $y1) / 2);
+ // *** Find the width/height middle points
+ $boxXMiddle = (($x2 - $x1) / 2);
+ $boxYMiddle = (($y2 - $y1) / 2);
- // *** Box middle - half the text width/height
- $xPos = ($x1 + $boxXMiddle) - ($textWidth / 2);
- $yPos = ($y1 + $boxYMiddle) - ($textHeight / 2);
+ // *** Box middle - half the text width/height
+ $xPos = ($x1 + $boxXMiddle) - ($textWidth / 2);
+ $yPos = ($y1 + $boxYMiddle) - ($textHeight / 2);
- $pos = $xPos . 'x' . $yPos;
+ $pos = $xPos . 'x' . $yPos;
- $this->addText($text, $pos, $padding = 0, $fontColor, $fontSize, $angle, $font);
+ $this->addText($text, $pos, $padding = 0, $fontColor, $fontSize, $angle, $font);
- }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function calculateCaptionBoxPosition($side, $thickness, $padding)
- {
- $positionArray = array();
+ private function calculateCaptionBoxPosition($side, $thickness, $padding)
+ {
+ $positionArray = array();
- switch ($side)
- {
- case 't':
- $positionArray['x1'] = 0;
- $positionArray['y1'] = $padding;
- $positionArray['x2'] = $this->width;
- $positionArray['y2'] = $thickness + $padding;
- break;
- case 'r':
- $positionArray['x1'] = $this->width - $thickness - $padding;
- $positionArray['y1'] = 0;
- $positionArray['x2'] = $this->width - $padding;
- $positionArray['y2'] = $this->height;
- break;
- case 'b':
- $positionArray['x1'] = 0;
- $positionArray['y1'] = $this->height - $thickness - $padding;
- $positionArray['x2'] = $this->width;
- $positionArray['y2'] = $this->height - $padding;
- break;
- case 'l':
- $positionArray['x1'] = $padding;
- $positionArray['y1'] = 0;
- $positionArray['x2'] = $thickness + $padding;
- $positionArray['y2'] = $this->height;
- break;
+ switch ($side)
+ {
+ case 't':
+ $positionArray['x1'] = 0;
+ $positionArray['y1'] = $padding;
+ $positionArray['x2'] = $this->width;
+ $positionArray['y2'] = $thickness + $padding;
+ break;
+ case 'r':
+ $positionArray['x1'] = $this->width - $thickness - $padding;
+ $positionArray['y1'] = 0;
+ $positionArray['x2'] = $this->width - $padding;
+ $positionArray['y2'] = $this->height;
+ break;
+ case 'b':
+ $positionArray['x1'] = 0;
+ $positionArray['y1'] = $this->height - $thickness - $padding;
+ $positionArray['x2'] = $this->width;
+ $positionArray['y2'] = $this->height - $padding;
+ break;
+ case 'l':
+ $positionArray['x1'] = $padding;
+ $positionArray['y1'] = 0;
+ $positionArray['x2'] = $thickness + $padding;
+ $positionArray['y2'] = $this->height;
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return $positionArray;
+ return $positionArray;
- }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Get EXIF Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function getExif($debug = false)
- # Author: Jarrod Oberto
- # Date: 07-05-2011
- # Purpose: Get image EXIF data
- # Param in: n/a
- # Param out: An associate array of EXIF data
- # Reference:
- # Notes:
- # 23 May 13 : added orientation flag -jco
- #
- {
+ public function getExif($debug = false)
+ # Author: Jarrod Oberto
+ # Date: 07-05-2011
+ # Purpose: Get image EXIF data
+ # Param in: n/a
+ # Param out: An associate array of EXIF data
+ # Reference:
+ # Notes:
+ # 23 May 13 : added orientation flag -jco
+ #
+ {
- if ( ! $this->debug || ! $debug)
- {
- $debug = false;
- }
+ if ( ! $this->debug || ! $debug)
+ {
+ $debug = false;
+ }
- // *** Check all is good - check the EXIF library exists and the file exists, too.
- if ( ! $this->testEXIFInstalled())
- {
- if ($debug)
- {
- throw new Exception('The EXIF Library is not installed.');
- }
- else
- {
- return array();
- }
- };
- if ( ! file_exists($this->fileName))
- {
- if ($debug)
- {
- throw new Exception('Image not found.');
- }
- else
- {
- return array();
- }
- };
- if ($this->fileExtension != '.jpg')
- {
- if ($debug)
- {
- throw new Exception('Metadata not supported for this image type.');
- }
- else
- {
- return array();
- }
- };
- $exifData = exif_read_data($this->fileName, 'IFD0');
+ // *** Check all is good - check the EXIF library exists and the file exists, too.
+ if ( ! $this->testEXIFInstalled())
+ {
+ if ($debug)
+ {
+ throw new Exception('The EXIF Library is not installed.');
+ }
+ else
+ {
+ return array();
+ }
+ };
+ if ( ! file_exists($this->fileName))
+ {
+ if ($debug)
+ {
+ throw new Exception('Image not found.');
+ }
+ else
+ {
+ return array();
+ }
+ };
+ if ($this->fileExtension != '.jpg')
+ {
+ if ($debug)
+ {
+ throw new Exception('Metadata not supported for this image type.');
+ }
+ else
+ {
+ return array();
+ }
+ };
+ $exifData = exif_read_data($this->fileName, 'IFD0');
- // *** Format the apperture value
- $ev = $exifData['ApertureValue'];
- $apPeicesArray = explode('/', $ev);
- if (count($apPeicesArray) == 2)
- {
- $apertureValue = round($apPeicesArray[0] / $apPeicesArray[1], 2, PHP_ROUND_HALF_DOWN) . ' EV';
- }
- else
- {
- $apertureValue = '';
- }
+ // *** Format the apperture value
+ $ev = $exifData['ApertureValue'];
+ $apPeicesArray = explode('/', $ev);
+ if (count($apPeicesArray) == 2)
+ {
+ $apertureValue = round($apPeicesArray[0] / $apPeicesArray[1], 2, PHP_ROUND_HALF_DOWN) . ' EV';
+ }
+ else
+ {
+ $apertureValue = '';
+ }
- // *** Format the focal length
- $focalLength = $exifData['FocalLength'];
- $flPeicesArray = explode('/', $focalLength);
- if (count($flPeicesArray) == 2)
- {
- $focalLength = $flPeicesArray[0] / $flPeicesArray[1] . '.0 mm';
- }
- else
- {
- $focalLength = '';
- }
+ // *** Format the focal length
+ $focalLength = $exifData['FocalLength'];
+ $flPeicesArray = explode('/', $focalLength);
+ if (count($flPeicesArray) == 2)
+ {
+ $focalLength = $flPeicesArray[0] / $flPeicesArray[1] . '.0 mm';
+ }
+ else
+ {
+ $focalLength = '';
+ }
- // *** Format fNumber
- $fNumber = $exifData['FNumber'];
- $fnPeicesArray = explode('/', $fNumber);
- if (count($fnPeicesArray) == 2)
- {
- $fNumber = $fnPeicesArray[0] / $fnPeicesArray[1];
- }
- else
- {
- $fNumber = '';
- }
+ // *** Format fNumber
+ $fNumber = $exifData['FNumber'];
+ $fnPeicesArray = explode('/', $fNumber);
+ if (count($fnPeicesArray) == 2)
+ {
+ $fNumber = $fnPeicesArray[0] / $fnPeicesArray[1];
+ }
+ else
+ {
+ $fNumber = '';
+ }
- // *** Resolve ExposureProgram
- if (isset($exifData['ExposureProgram']))
- {
- $ep = $exifData['ExposureProgram'];
- }
- if (isset($ep))
- {
- $ep = $this->resolveExposureProgram($ep);
- }
+ // *** Resolve ExposureProgram
+ if (isset($exifData['ExposureProgram']))
+ {
+ $ep = $exifData['ExposureProgram'];
+ }
+ if (isset($ep))
+ {
+ $ep = $this->resolveExposureProgram($ep);
+ }
- // *** Resolve MeteringMode
- $mm = $exifData['MeteringMode'];
- $mm = $this->resolveMeteringMode($mm);
+ // *** Resolve MeteringMode
+ $mm = $exifData['MeteringMode'];
+ $mm = $this->resolveMeteringMode($mm);
- // *** Resolve Flash
- $flash = $exifData['Flash'];
- $flash = $this->resolveFlash($flash);
+ // *** Resolve Flash
+ $flash = $exifData['Flash'];
+ $flash = $this->resolveFlash($flash);
- if (isset($exifData['Make']))
- {
- $exifDataArray['make'] = $exifData['Make'];
- }
- else
- {
- $exifDataArray['make'] = '';
- }
+ if (isset($exifData['Make']))
+ {
+ $exifDataArray['make'] = $exifData['Make'];
+ }
+ else
+ {
+ $exifDataArray['make'] = '';
+ }
- if (isset($exifData['Model']))
- {
- $exifDataArray['model'] = $exifData['Model'];
- }
- else
- {
- $exifDataArray['model'] = '';
- }
+ if (isset($exifData['Model']))
+ {
+ $exifDataArray['model'] = $exifData['Model'];
+ }
+ else
+ {
+ $exifDataArray['model'] = '';
+ }
- if (isset($exifData['DateTime']))
- {
- $exifDataArray['date'] = $exifData['DateTime'];
- }
- else
- {
- $exifDataArray['date'] = '';
- }
+ if (isset($exifData['DateTime']))
+ {
+ $exifDataArray['date'] = $exifData['DateTime'];
+ }
+ else
+ {
+ $exifDataArray['date'] = '';
+ }
- if (isset($exifData['ExposureTime']))
- {
- $exifDataArray['exposure time'] = $exifData['ExposureTime'] . ' sec.';
- }
- else
- {
- $exifDataArray['exposure time'] = '';
- }
+ if (isset($exifData['ExposureTime']))
+ {
+ $exifDataArray['exposure time'] = $exifData['ExposureTime'] . ' sec.';
+ }
+ else
+ {
+ $exifDataArray['exposure time'] = '';
+ }
- if ($apertureValue != '')
- {
- $exifDataArray['aperture value'] = $apertureValue;
- }
- else
- {
- $exifDataArray['aperture value'] = '';
- }
+ if ($apertureValue != '')
+ {
+ $exifDataArray['aperture value'] = $apertureValue;
+ }
+ else
+ {
+ $exifDataArray['aperture value'] = '';
+ }
- if (isset($exifData['COMPUTED']['ApertureFNumber']))
- {
- $exifDataArray['f-stop'] = $exifData['COMPUTED']['ApertureFNumber'];
- }
- else
- {
- $exifDataArray['f-stop'] = '';
- }
+ if (isset($exifData['COMPUTED']['ApertureFNumber']))
+ {
+ $exifDataArray['f-stop'] = $exifData['COMPUTED']['ApertureFNumber'];
+ }
+ else
+ {
+ $exifDataArray['f-stop'] = '';
+ }
- if (isset($exifData['FNumber']))
- {
- $exifDataArray['fnumber'] = $exifData['FNumber'];
- }
- else
- {
- $exifDataArray['fnumber'] = '';
- }
+ if (isset($exifData['FNumber']))
+ {
+ $exifDataArray['fnumber'] = $exifData['FNumber'];
+ }
+ else
+ {
+ $exifDataArray['fnumber'] = '';
+ }
- if ($fNumber != '')
- {
- $exifDataArray['fnumber value'] = $fNumber;
- }
- else
- {
- $exifDataArray['fnumber value'] = '';
- }
+ if ($fNumber != '')
+ {
+ $exifDataArray['fnumber value'] = $fNumber;
+ }
+ else
+ {
+ $exifDataArray['fnumber value'] = '';
+ }
- if (isset($exifData['ISOSpeedRatings']))
- {
- $exifDataArray['iso'] = $exifData['ISOSpeedRatings'];
- }
- else
- {
- $exifDataArray['iso'] = '';
- }
+ if (isset($exifData['ISOSpeedRatings']))
+ {
+ $exifDataArray['iso'] = $exifData['ISOSpeedRatings'];
+ }
+ else
+ {
+ $exifDataArray['iso'] = '';
+ }
- if ($focalLength != '')
- {
- $exifDataArray['focal length'] = $focalLength;
- }
- else
- {
- $exifDataArray['focal length'] = '';
- }
+ if ($focalLength != '')
+ {
+ $exifDataArray['focal length'] = $focalLength;
+ }
+ else
+ {
+ $exifDataArray['focal length'] = '';
+ }
- if (isset($ep))
- {
- $exifDataArray['exposure program'] = $ep;
- }
- else
- {
- $exifDataArray['exposure program'] = '';
- }
+ if (isset($ep))
+ {
+ $exifDataArray['exposure program'] = $ep;
+ }
+ else
+ {
+ $exifDataArray['exposure program'] = '';
+ }
- if ($mm != '')
- {
- $exifDataArray['metering mode'] = $mm;
- }
- else
- {
- $exifDataArray['metering mode'] = '';
- }
+ if ($mm != '')
+ {
+ $exifDataArray['metering mode'] = $mm;
+ }
+ else
+ {
+ $exifDataArray['metering mode'] = '';
+ }
- if ($flash != '')
- {
- $exifDataArray['flash status'] = $flash;
- }
- else
- {
- $exifDataArray['flash status'] = '';
- }
+ if ($flash != '')
+ {
+ $exifDataArray['flash status'] = $flash;
+ }
+ else
+ {
+ $exifDataArray['flash status'] = '';
+ }
- if (isset($exifData['Artist']))
- {
- $exifDataArray['creator'] = $exifData['Artist'];
- }
- else
- {
- $exifDataArray['creator'] = '';
- }
+ if (isset($exifData['Artist']))
+ {
+ $exifDataArray['creator'] = $exifData['Artist'];
+ }
+ else
+ {
+ $exifDataArray['creator'] = '';
+ }
- if (isset($exifData['Copyright']))
- {
- $exifDataArray['copyright'] = $exifData['Copyright'];
- }
- else
- {
- $exifDataArray['copyright'] = '';
- }
+ if (isset($exifData['Copyright']))
+ {
+ $exifDataArray['copyright'] = $exifData['Copyright'];
+ }
+ else
+ {
+ $exifDataArray['copyright'] = '';
+ }
- // *** Orientation
- if (isset($exifData['Orientation']))
- {
- $exifDataArray['orientation'] = $exifData['Orientation'];
- }
- else
- {
- $exifDataArray['orientation'] = '';
- }
+ // *** Orientation
+ if (isset($exifData['Orientation']))
+ {
+ $exifDataArray['orientation'] = $exifData['Orientation'];
+ }
+ else
+ {
+ $exifDataArray['orientation'] = '';
+ }
- return $exifDataArray;
- }
+ return $exifDataArray;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function resolveExposureProgram($ep)
- {
- switch ($ep)
- {
- case 0:
- $ep = '';
- break;
- case 1:
- $ep = 'manual';
- break;
- case 2:
- $ep = 'normal program';
- break;
- case 3:
- $ep = 'aperture priority';
- break;
- case 4:
- $ep = 'shutter priority';
- break;
- case 5:
- $ep = 'creative program';
- break;
- case 6:
- $ep = 'action program';
- break;
- case 7:
- $ep = 'portrait mode';
- break;
- case 8:
- $ep = 'landscape mode';
- break;
+ private function resolveExposureProgram($ep)
+ {
+ switch ($ep)
+ {
+ case 0:
+ $ep = '';
+ break;
+ case 1:
+ $ep = 'manual';
+ break;
+ case 2:
+ $ep = 'normal program';
+ break;
+ case 3:
+ $ep = 'aperture priority';
+ break;
+ case 4:
+ $ep = 'shutter priority';
+ break;
+ case 5:
+ $ep = 'creative program';
+ break;
+ case 6:
+ $ep = 'action program';
+ break;
+ case 7:
+ $ep = 'portrait mode';
+ break;
+ case 8:
+ $ep = 'landscape mode';
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return $ep;
- }
+ return $ep;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function resolveMeteringMode($mm)
- {
- switch ($mm)
- {
- case 0:
- $mm = 'unknown';
- break;
- case 1:
- $mm = 'average';
- break;
- case 2:
- $mm = 'center weighted average';
- break;
- case 3:
- $mm = 'spot';
- break;
- case 4:
- $mm = 'multi spot';
- break;
- case 5:
- $mm = 'pattern';
- break;
- case 6:
- $mm = 'partial';
- break;
- case 255:
- $mm = 'other';
- break;
+ private function resolveMeteringMode($mm)
+ {
+ switch ($mm)
+ {
+ case 0:
+ $mm = 'unknown';
+ break;
+ case 1:
+ $mm = 'average';
+ break;
+ case 2:
+ $mm = 'center weighted average';
+ break;
+ case 3:
+ $mm = 'spot';
+ break;
+ case 4:
+ $mm = 'multi spot';
+ break;
+ case 5:
+ $mm = 'pattern';
+ break;
+ case 6:
+ $mm = 'partial';
+ break;
+ case 255:
+ $mm = 'other';
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return $mm;
- }
+ return $mm;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function resolveFlash($flash)
- {
- switch ($flash)
- {
- case 0:
- $flash = 'flash did not fire';
- break;
- case 1:
- $flash = 'flash fired';
- break;
- case 5:
- $flash = 'strobe return light not detected';
- break;
- case 7:
- $flash = 'strobe return light detected';
- break;
- case 9:
- $flash = 'flash fired, compulsory flash mode';
- break;
- case 13:
- $flash = 'flash fired, compulsory flash mode, return light not detected';
- break;
- case 15:
- $flash = 'flash fired, compulsory flash mode, return light detected';
- break;
- case 16:
- $flash = 'flash did not fire, compulsory flash mode';
- break;
- case 24:
- $flash = 'flash did not fire, auto mode';
- break;
- case 25:
- $flash = 'flash fired, auto mode';
- break;
- case 29:
- $flash = 'flash fired, auto mode, return light not detected';
- break;
- case 31:
- $flash = 'flash fired, auto mode, return light detected';
- break;
- case 32:
- $flash = 'no flash function';
- break;
- case 65:
- $flash = 'flash fired, red-eye reduction mode';
- break;
- case 69:
- $flash = 'flash fired, red-eye reduction mode, return light not detected';
- break;
- case 71:
- $flash = 'flash fired, red-eye reduction mode, return light detected';
- break;
- case 73:
- $flash = 'flash fired, compulsory flash mode, red-eye reduction mode';
- break;
- case 77:
- $flash = 'flash fired, compulsory flash mode, red-eye reduction mode, return light not detected';
- break;
- case 79:
- $flash = 'flash fired, compulsory flash mode, red-eye reduction mode, return light detected';
- break;
- case 89:
- $flash = 'flash fired, auto mode, red-eye reduction mode';
- break;
- case 93:
- $flash = 'flash fired, auto mode, return light not detected, red-eye reduction mode';
- break;
- case 95:
- $flash = 'flash fired, auto mode, return light detected, red-eye reduction mode';
- break;
+ private function resolveFlash($flash)
+ {
+ switch ($flash)
+ {
+ case 0:
+ $flash = 'flash did not fire';
+ break;
+ case 1:
+ $flash = 'flash fired';
+ break;
+ case 5:
+ $flash = 'strobe return light not detected';
+ break;
+ case 7:
+ $flash = 'strobe return light detected';
+ break;
+ case 9:
+ $flash = 'flash fired, compulsory flash mode';
+ break;
+ case 13:
+ $flash = 'flash fired, compulsory flash mode, return light not detected';
+ break;
+ case 15:
+ $flash = 'flash fired, compulsory flash mode, return light detected';
+ break;
+ case 16:
+ $flash = 'flash did not fire, compulsory flash mode';
+ break;
+ case 24:
+ $flash = 'flash did not fire, auto mode';
+ break;
+ case 25:
+ $flash = 'flash fired, auto mode';
+ break;
+ case 29:
+ $flash = 'flash fired, auto mode, return light not detected';
+ break;
+ case 31:
+ $flash = 'flash fired, auto mode, return light detected';
+ break;
+ case 32:
+ $flash = 'no flash function';
+ break;
+ case 65:
+ $flash = 'flash fired, red-eye reduction mode';
+ break;
+ case 69:
+ $flash = 'flash fired, red-eye reduction mode, return light not detected';
+ break;
+ case 71:
+ $flash = 'flash fired, red-eye reduction mode, return light detected';
+ break;
+ case 73:
+ $flash = 'flash fired, compulsory flash mode, red-eye reduction mode';
+ break;
+ case 77:
+ $flash = 'flash fired, compulsory flash mode, red-eye reduction mode, return light not detected';
+ break;
+ case 79:
+ $flash = 'flash fired, compulsory flash mode, red-eye reduction mode, return light detected';
+ break;
+ case 89:
+ $flash = 'flash fired, auto mode, red-eye reduction mode';
+ break;
+ case 93:
+ $flash = 'flash fired, auto mode, return light not detected, red-eye reduction mode';
+ break;
+ case 95:
+ $flash = 'flash fired, auto mode, return light detected, red-eye reduction mode';
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return $flash;
+ return $flash;
- }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Get IPTC Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Write IPTC Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function writeIPTCcaption($value)
- # Caption
- {
- $this->writeIPTC(120, $value);
- }
+ public function writeIPTCcaption($value)
+ # Caption
+ {
+ $this->writeIPTC(120, $value);
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- public function writeIPTCwriter($value)
- {
- //$this->writeIPTC(65, $value);
- }
+ public function writeIPTCwriter($value)
+ {
+ //$this->writeIPTC(65, $value);
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function writeIPTC($dat, $value)
- {
+ private function writeIPTC($dat, $value)
+ {
- # LIMIT TO JPG
+ # LIMIT TO JPG
- $caption_block = $this->iptc_maketag(2, $dat, $value);
- $image_string = iptcembed($caption_block, $this->fileName);
- file_put_contents('iptc.jpg', $image_string);
- }
+ $caption_block = $this->iptc_maketag(2, $dat, $value);
+ $image_string = iptcembed($caption_block, $this->fileName);
+ file_put_contents('iptc.jpg', $image_string);
+ }
## --------------------------------------------------------
- private function iptc_maketag($rec, $dat, $val)
- # Author: Thies C. Arntzen
- # Purpose: Function to format the new IPTC text
- # Param in: $rec: Application record. (We’re working with #2)
- # $dat: Index. (120 for caption, 118 for contact. See the IPTC IIM
- # specification:
- # http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
- # $val: Value/data/text. Make sure this is within the length
- # constraints of the IPTC IIM specification
- # Ref: http://blog.peterhaza.no/working-with-image-meta-data-in-exif-and-iptc-headers-from-php/
- # http://php.net/manual/en/function.iptcembed.php
- #
- {
- $len = strlen($val);
- if ($len < 0x8000)
- {
- return chr(0x1c) . chr($rec) . chr($dat) .
- chr($len >> 8) .
- chr($len & 0xff) .
- $val;
- }
- else
- {
- return chr(0x1c) . chr($rec) . chr($dat) .
- chr(0x80) . chr(0x04) .
- chr(($len >> 24) & 0xff) .
- chr(($len >> 16) & 0xff) .
- chr(($len >> 8) & 0xff) .
- chr(($len) & 0xff) .
- $val;
- }
- }
+ private function iptc_maketag($rec, $dat, $val)
+ # Author: Thies C. Arntzen
+ # Purpose: Function to format the new IPTC text
+ # Param in: $rec: Application record. (We’re working with #2)
+ # $dat: Index. (120 for caption, 118 for contact. See the IPTC IIM
+ # specification:
+ # http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
+ # $val: Value/data/text. Make sure this is within the length
+ # constraints of the IPTC IIM specification
+ # Ref: http://blog.peterhaza.no/working-with-image-meta-data-in-exif-and-iptc-headers-from-php/
+ # http://php.net/manual/en/function.iptcembed.php
+ #
+ {
+ $len = strlen($val);
+ if ($len < 0x8000)
+ {
+ return chr(0x1c) . chr($rec) . chr($dat) .
+ chr($len >> 8) .
+ chr($len & 0xff) .
+ $val;
+ }
+ else
+ {
+ return chr(0x1c) . chr($rec) . chr($dat) .
+ chr(0x80) . chr(0x04) .
+ chr(($len >> 24) & 0xff) .
+ chr(($len >> 16) & 0xff) .
+ chr(($len >> 8) & 0xff) .
+ chr(($len) & 0xff) .
+ $val;
+ }
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Write XMP Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- //http://xmpphptoolkit.sourceforge.net/
+ //http://xmpphptoolkit.sourceforge.net/
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Add Text
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
- # Author: Jarrod Oberto
- # Date: 18-11-09
- # Purpose: Add text to an image
- # Param in:
- # Param out:
- # Reference: http://php.net/manual/en/function.imagettftext.php
- # Notes: Make sure you supply the font.
- #
- {
+ public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
+ # Author: Jarrod Oberto
+ # Date: 18-11-09
+ # Purpose: Add text to an image
+ # Param in:
+ # Param out:
+ # Reference: http://php.net/manual/en/function.imagettftext.php
+ # Notes: Make sure you supply the font.
+ #
+ {
- // *** Convert color
- $rgbArray = $this->formatColor($fontColor);
- $r = $rgbArray['r'];
- $g = $rgbArray['g'];
- $b = $rgbArray['b'];
+ // *** Convert color
+ $rgbArray = $this->formatColor($fontColor);
+ $r = $rgbArray['r'];
+ $g = $rgbArray['g'];
+ $b = $rgbArray['b'];
- // *** Get text font
- $font = $this->getTextFont($font);
+ // *** Get text font
+ $font = $this->getTextFont($font);
- // *** Get text size
- $textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
- $textWidth = $textSizeArray['width'];
- $textHeight = $textSizeArray['height'];
+ // *** Get text size
+ $textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
+ $textWidth = $textSizeArray['width'];
+ $textHeight = $textSizeArray['height'];
- // *** Find co-ords to place text
- $posArray = $this->calculatePosition($pos, $padding, $textWidth, $textHeight, false);
- $x = $posArray['width'];
- $y = $posArray['height'];
+ // *** Find co-ords to place text
+ $posArray = $this->calculatePosition($pos, $padding, $textWidth, $textHeight, false);
+ $x = $posArray['width'];
+ $y = $posArray['height'];
- $fontColor = imagecolorallocate($this->imageResized, $r, $g, $b);
+ $fontColor = imagecolorallocate($this->imageResized, $r, $g, $b);
- // *** Add text
- imagettftext($this->imageResized, $fontSize, $angle, $x, $y, $fontColor, $font, $text);
- }
+ // *** Add text
+ imagettftext($this->imageResized, $fontSize, $angle, $x, $y, $fontColor, $font, $text);
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function getTextFont($font)
- {
- // *** Font path (shou
- $fontPath = dirname(__FILE__) . '/' . $this->fontDir;
+ private function getTextFont($font)
+ {
+ // *** Font path (shou
+ $fontPath = dirname(__FILE__) . '/' . $this->fontDir;
- // *** The below is/may be needed depending on your version (see ref)
- putenv('GDFONTPATH=' . realpath('.'));
+ // *** The below is/may be needed depending on your version (see ref)
+ putenv('GDFONTPATH=' . realpath('.'));
- // *** Check if the passed in font exsits...
- if ($font == null || ! file_exists($font))
- {
+ // *** Check if the passed in font exsits...
+ if ($font == null || ! file_exists($font))
+ {
- // *** ...If not, default to this font.
- $font = $fontPath . '/arimo.ttf';
+ // *** ...If not, default to this font.
+ $font = $fontPath . '/arimo.ttf';
- // *** Check our default font exists...
- if ( ! file_exists($font))
- {
+ // *** Check our default font exists...
+ if ( ! file_exists($font))
+ {
- // *** If not, return false
- if ($this->debug)
- {
- throw new Exception('Font not found');
- }
- else
- {
- return false;
- }
- }
- }
+ // *** If not, return false
+ if ($this->debug)
+ {
+ throw new Exception('Font not found');
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
- return $font;
+ return $font;
- }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function getTextSize($fontSize, $angle, $font, $text)
- {
+ private function getTextSize($fontSize, $angle, $font, $text)
+ {
- // *** Define box (so we can get the width)
- $box = @imageTTFBbox($fontSize, $angle, $font, $text);
+ // *** Define box (so we can get the width)
+ $box = @imageTTFBbox($fontSize, $angle, $font, $text);
- // *** Get width of text from dimensions
- $textWidth = abs($box[4] - $box[0]);
+ // *** Get width of text from dimensions
+ $textWidth = abs($box[4] - $box[0]);
- // *** Get height of text from dimensions (should also be same as $fontSize)
- $textHeight = abs($box[5] - $box[1]);
+ // *** Get height of text from dimensions (should also be same as $fontSize)
+ $textHeight = abs($box[5] - $box[1]);
- return array( 'height' => $textHeight, 'width' => $textWidth );
- }
+ return array( 'height' => $textHeight, 'width' => $textWidth );
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
Add Watermark
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- public function addWatermark($watermarkImage, $pos, $padding = 0, $opacity = 0)
- # Author: Jarrod Oberto
- # Date: 18-11-09
- # Purpose: Add watermark image
- # Param in: (str) $watermark: The watermark image
- # (str) $pos: Could be a pre-determined position such as:
- # tl = top left,
- # t = top (middle),
- # tr = top right,
- # l = left,
- # m = middle,
- # r = right,
- # bl = bottom left,
- # b = bottom (middle),
- # br = bottom right
- # Or, it could be a co-ordinate position such as: 50x100
- #
- # (int) $padding: If using a pre-determined position you can
- # adjust the padding from the edges by passing an amount
- # in pixels. If using co-ordinates, this value is ignored.
- # Param out:
- # Reference: http://www.php.net/manual/en/image.examples-watermark.php
- # Notes: Based on example in reference.
- #
- #
- {
+ public function addWatermark($watermarkImage, $pos, $padding = 0, $opacity = 0)
+ # Author: Jarrod Oberto
+ # Date: 18-11-09
+ # Purpose: Add watermark image
+ # Param in: (str) $watermark: The watermark image
+ # (str) $pos: Could be a pre-determined position such as:
+ # tl = top left,
+ # t = top (middle),
+ # tr = top right,
+ # l = left,
+ # m = middle,
+ # r = right,
+ # bl = bottom left,
+ # b = bottom (middle),
+ # br = bottom right
+ # Or, it could be a co-ordinate position such as: 50x100
+ #
+ # (int) $padding: If using a pre-determined position you can
+ # adjust the padding from the edges by passing an amount
+ # in pixels. If using co-ordinates, this value is ignored.
+ # Param out:
+ # Reference: http://www.php.net/manual/en/image.examples-watermark.php
+ # Notes: Based on example in reference.
+ #
+ #
+ {
- // Load the stamp and the photo to apply the watermark to
- $stamp = $this->openImage($watermarkImage); # stamp
- $im = $this->imageResized; # photo
+ // Load the stamp and the photo to apply the watermark to
+ $stamp = $this->openImage($watermarkImage); # stamp
+ $im = $this->imageResized; # photo
- // *** Get stamps width and height
- $sx = imagesx($stamp);
- $sy = imagesy($stamp);
+ // *** Get stamps width and height
+ $sx = imagesx($stamp);
+ $sy = imagesy($stamp);
- // *** Find co-ords to place image
- $posArray = $this->calculatePosition($pos, $padding, $sx, $sy);
- $x = $posArray['width'];
- $y = $posArray['height'];
+ // *** Find co-ords to place image
+ $posArray = $this->calculatePosition($pos, $padding, $sx, $sy);
+ $x = $posArray['width'];
+ $y = $posArray['height'];
- // *** Set watermark opacity
- if (fix_strtolower(strrchr($watermarkImage, '.')) == '.png')
- {
+ // *** Set watermark opacity
+ if (fix_strtolower(strrchr($watermarkImage, '.')) == '.png')
+ {
- $opacity = $this->invertTransparency($opacity, 100);
- $this->filterOpacity($stamp, $opacity);
- }
+ $opacity = $this->invertTransparency($opacity, 100);
+ $this->filterOpacity($stamp, $opacity);
+ }
- // Copy the watermark image onto our photo
- imagecopy($im, $stamp, $x, $y, 0, 0, imagesx($stamp), imagesy($stamp));
+ // Copy the watermark image onto our photo
+ imagecopy($im, $stamp, $x, $y, 0, 0, imagesx($stamp), imagesy($stamp));
- }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $upperLeft = true)
- #
- # Author: Jarrod Oberto
- # Date: 08-05-11
- # Purpose: Calculate the x, y pixel cordinates of the asset to place
- # Params in: (str) $pos: Either something like: "tl", "l", "br" or an
- # exact position like: "100x50"
- # (int) $padding: The amount of padding from the edge. Only
- # used for the predefined $pos.
- # (int) $assetWidth: The width of the asset to add to the image
- # (int) $assetHeight: The height of the asset to add to the image
- # (bol) $upperLeft: if true, the asset will be positioned based
- # on the upper left x, y coords. If false, it means you're
- # using the lower left as the basepoint and this will
- # convert it to the upper left position
- # Params out:
- # NOTE: this is done from the UPPER left corner!! But will convert lower
- # left basepoints to upper left if $upperleft is set to false
- #
- #
- {
- $pos = fix_strtolower($pos);
+ private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $upperLeft = true)
+ #
+ # Author: Jarrod Oberto
+ # Date: 08-05-11
+ # Purpose: Calculate the x, y pixel cordinates of the asset to place
+ # Params in: (str) $pos: Either something like: "tl", "l", "br" or an
+ # exact position like: "100x50"
+ # (int) $padding: The amount of padding from the edge. Only
+ # used for the predefined $pos.
+ # (int) $assetWidth: The width of the asset to add to the image
+ # (int) $assetHeight: The height of the asset to add to the image
+ # (bol) $upperLeft: if true, the asset will be positioned based
+ # on the upper left x, y coords. If false, it means you're
+ # using the lower left as the basepoint and this will
+ # convert it to the upper left position
+ # Params out:
+ # NOTE: this is done from the UPPER left corner!! But will convert lower
+ # left basepoints to upper left if $upperleft is set to false
+ #
+ #
+ {
+ $pos = fix_strtolower($pos);
- // *** If co-ords have been entered
- if (strstr($pos, 'x'))
- {
- $pos = str_replace(' ', '', $pos);
+ // *** If co-ords have been entered
+ if (strstr($pos, 'x'))
+ {
+ $pos = str_replace(' ', '', $pos);
- $xyArray = explode('x', $pos);
- list($width, $height) = $xyArray;
+ $xyArray = explode('x', $pos);
+ list($width, $height) = $xyArray;
- }
- else
- {
+ }
+ else
+ {
- switch ($pos)
- {
- case 'tl':
- $width = 0 + $padding;
- $height = 0 + $padding;
- break;
+ switch ($pos)
+ {
+ case 'tl':
+ $width = 0 + $padding;
+ $height = 0 + $padding;
+ break;
- case 't':
- $width = ($this->width / 2) - ($assetWidth / 2);
- $height = 0 + $padding;
- break;
+ case 't':
+ $width = ($this->width / 2) - ($assetWidth / 2);
+ $height = 0 + $padding;
+ break;
- case 'tr':
- $width = $this->width - $assetWidth - $padding;
- $height = 0 + $padding;;
- break;
+ case 'tr':
+ $width = $this->width - $assetWidth - $padding;
+ $height = 0 + $padding;;
+ break;
- case 'l':
- $width = 0 + $padding;
- $height = ($this->height / 2) - ($assetHeight / 2);
- break;
+ case 'l':
+ $width = 0 + $padding;
+ $height = ($this->height / 2) - ($assetHeight / 2);
+ break;
- case 'm':
- $width = ($this->width / 2) - ($assetWidth / 2);
- $height = ($this->height / 2) - ($assetHeight / 2);
- break;
+ case 'm':
+ $width = ($this->width / 2) - ($assetWidth / 2);
+ $height = ($this->height / 2) - ($assetHeight / 2);
+ break;
- case 'r':
- $width = $this->width - $assetWidth - $padding;
- $height = ($this->height / 2) - ($assetHeight / 2);
- break;
+ case 'r':
+ $width = $this->width - $assetWidth - $padding;
+ $height = ($this->height / 2) - ($assetHeight / 2);
+ break;
- case 'bl':
- $width = 0 + $padding;
- $height = $this->height - $assetHeight - $padding;
- break;
+ case 'bl':
+ $width = 0 + $padding;
+ $height = $this->height - $assetHeight - $padding;
+ break;
- case 'b':
- $width = ($this->width / 2) - ($assetWidth / 2);
- $height = $this->height - $assetHeight - $padding;
- break;
+ case 'b':
+ $width = ($this->width / 2) - ($assetWidth / 2);
+ $height = $this->height - $assetHeight - $padding;
+ break;
- case 'br':
- $width = $this->width - $assetWidth - $padding;
- $height = $this->height - $assetHeight - $padding;
- break;
+ case 'br':
+ $width = $this->width - $assetWidth - $padding;
+ $height = $this->height - $assetHeight - $padding;
+ break;
- default:
- $width = 0;
- $height = 0;
- break;
- }
- }
+ default:
+ $width = 0;
+ $height = 0;
+ break;
+ }
+ }
- if ( ! $upperLeft)
- {
- $height = $height + $assetHeight;
- }
+ if ( ! $upperLeft)
+ {
+ $height = $height + $assetHeight;
+ }
- return array( 'width' => $width, 'height' => $height );
- }
+ return array( 'width' => $width, 'height' => $height );
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function filterOpacity(&$img, $opacity = 75)
- #
- # Author: aiden dot mail at freemail dot hu
- # Author date: 29-03-08 08:16
- # Date added: 08-05-11
- # Purpose: Change opacity of image
- # Params in: $img: Image resource id
- # (int) $opacity: the opacity amount: 0-100, 100 being not opaque.
- # Params out: (bool) true on success, else false
- # Ref: http://www.php.net/manual/en/function.imagefilter.php#82162
- # Notes: png only
- #
- {
+ private function filterOpacity(&$img, $opacity = 75)
+ #
+ # Author: aiden dot mail at freemail dot hu
+ # Author date: 29-03-08 08:16
+ # Date added: 08-05-11
+ # Purpose: Change opacity of image
+ # Params in: $img: Image resource id
+ # (int) $opacity: the opacity amount: 0-100, 100 being not opaque.
+ # Params out: (bool) true on success, else false
+ # Ref: http://www.php.net/manual/en/function.imagefilter.php#82162
+ # Notes: png only
+ #
+ {
- if ( ! isset($opacity))
- {
- return false;
- }
+ if ( ! isset($opacity))
+ {
+ return false;
+ }
- if ($opacity == 100)
- {
- return true;
- }
+ if ($opacity == 100)
+ {
+ return true;
+ }
- $opacity /= 100;
+ $opacity /= 100;
- //get image width and height
- $w = imagesx($img);
- $h = imagesy($img);
+ //get image width and height
+ $w = imagesx($img);
+ $h = imagesy($img);
- //turn alpha blending off
- imagealphablending($img, false);
+ //turn alpha blending off
+ imagealphablending($img, false);
- //find the most opaque pixel in the image (the one with the smallest alpha value)
- $minalpha = 127;
- for ($x = 0; $x < $w; $x++)
- {
- for ($y = 0; $y < $h; $y++)
- {
- $alpha = (imagecolorat($img, $x, $y) >> 24) & 0xFF;
- if ($alpha < $minalpha)
- {
- $minalpha = $alpha;
- }
- }
- }
+ //find the most opaque pixel in the image (the one with the smallest alpha value)
+ $minalpha = 127;
+ for ($x = 0; $x < $w; $x++)
+ {
+ for ($y = 0; $y < $h; $y++)
+ {
+ $alpha = (imagecolorat($img, $x, $y) >> 24) & 0xFF;
+ if ($alpha < $minalpha)
+ {
+ $minalpha = $alpha;
+ }
+ }
+ }
- //loop through image pixels and modify alpha for each
- for ($x = 0; $x < $w; $x++)
- {
- for ($y = 0; $y < $h; $y++)
- {
- //get current alpha value (represents the TANSPARENCY!)
- $colorxy = imagecolorat($img, $x, $y);
- $alpha = ($colorxy >> 24) & 0xFF;
- //calculate new alpha
- if ($minalpha !== 127)
- {
- $alpha = 127 + 127 * $opacity * ($alpha - 127) / (127 - $minalpha);
- }
- else
- {
- $alpha += 127 * $opacity;
- }
- //get the color index with new alpha
- $alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha);
- //set pixel with the new color + opacity
- if ( ! imagesetpixel($img, $x, $y, $alphacolorxy))
- {
+ //loop through image pixels and modify alpha for each
+ for ($x = 0; $x < $w; $x++)
+ {
+ for ($y = 0; $y < $h; $y++)
+ {
+ //get current alpha value (represents the TANSPARENCY!)
+ $colorxy = imagecolorat($img, $x, $y);
+ $alpha = ($colorxy >> 24) & 0xFF;
+ //calculate new alpha
+ if ($minalpha !== 127)
+ {
+ $alpha = 127 + 127 * $opacity * ($alpha - 127) / (127 - $minalpha);
+ }
+ else
+ {
+ $alpha += 127 * $opacity;
+ }
+ //get the color index with new alpha
+ $alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha);
+ //set pixel with the new color + opacity
+ if ( ! imagesetpixel($img, $x, $y, $alphacolorxy))
+ {
- return false;
- }
- }
- }
+ return false;
+ }
+ }
+ }
- return true;
- }
+ return true;
+ }
## --------------------------------------------------------
- private function openImage($file)
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose:
- # Param in:
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
+ private function openImage($file)
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose:
+ # Param in:
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
- if ( ! file_exists($file) && ! $this->checkStringStartsWith('http://', $file) && ! $this->checkStringStartsWith('https://', $file) )
- {
- if ($this->debug)
- {
- throw new Exception('Image not found.');
- }
- else
- {
- throw new Exception();
- }
- };
+ if ( ! file_exists($file) && ! $this->checkStringStartsWith('http://', $file) && ! $this->checkStringStartsWith('https://', $file) )
+ {
+ if ($this->debug)
+ {
+ throw new Exception('Image not found.');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ };
- // *** Get extension / image type
- $extension = mime_content_type($file);
- $extension = fix_strtolower($extension);
- $extension = str_replace('image/', '', $extension);
- switch ($extension)
- {
- case 'jpg':
- case 'jpeg':
- $img = @imagecreatefromjpeg($file);
- break;
- case 'gif':
- $img = @imagecreatefromgif($file);
- break;
- case 'png':
- $img = @imagecreatefrompng($file);
- break;
- case 'bmp':
- $img = @$this->imagecreatefrombmp($file);
- break;
- case 'psd':
- case 'vnd.adobe.photoshop':
- $img = @$this->imagecreatefrompsd($file);
- break;
+ // *** Get extension / image type
+ $extension = mime_content_type($file);
+ $extension = fix_strtolower($extension);
+ $extension = str_replace('image/', '', $extension);
+ switch ($extension)
+ {
+ case 'jpg':
+ case 'jpeg':
+ $img = @imagecreatefromjpeg($file);
+ break;
+ case 'webp':
+ $img = @imagecreatefromwebp($file);
+ break;
+ case 'gif':
+ $img = @imagecreatefromgif($file);
+ break;
+ case 'png':
+ $img = @imagecreatefrompng($file);
+ break;
+ case 'bmp':
+ case 'x-ms-bmp':
+ $img = @$this->imagecreatefrombmp($file);
+ break;
+ case 'psd':
+ case 'vnd.adobe.photoshop':
+ $img = @$this->imagecreatefrompsd($file);
+ break;
- // ... etc
+ // ... etc
- default:
- $img = false;
- break;
- }
+ default:
+ $img = false;
+ break;
+ }
- return $img;
- }
+ return $img;
+ }
## --------------------------------------------------------
- public function reset()
- #
- # Author: Jarrod Oberto
- # Date: 30-08-11
- # Purpose: Reset the resource (allow further editing)
- # Params in:
- # Params out:
- # Notes:
- #
- {
- $this->__construct($this->fileName);
- }
+ public function reset()
+ #
+ # Author: Jarrod Oberto
+ # Date: 30-08-11
+ # Purpose: Reset the resource (allow further editing)
+ # Params in:
+ # Params out:
+ # Notes:
+ #
+ {
+ $this->__construct($this->fileName);
+ }
## --------------------------------------------------------
- public function saveImage($savePath, $imageQuality = "100")
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose: Saves the image
- # Param in: $savePath: Where to save the image including filename:
- # $imageQuality: image quality you want the image saved at 0-100
- # Param out: n/a
- # Reference:
- # Notes: * gif doesn't have a quality parameter
- # * jpg has a quality setting 0-100 (100 being the best)
- # * png has a quality setting 0-9 (0 being the best)
- #
- # * bmp files have no native support for bmp files. We use a
- # third party class to save as bmp.
- {
+ public function saveImage($savePath, $imageQuality = "100")
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose: Saves the image
+ # Param in: $savePath: Where to save the image including filename:
+ # $imageQuality: image quality you want the image saved at 0-100
+ # Param out: n/a
+ # Reference:
+ # Notes: * gif doesn't have a quality parameter
+ # * jpg has a quality setting 0-100 (100 being the best)
+ # * webp has a quality setting 0-100 (100 being the best)
+ # * png has a quality setting 0-9 (0 being the best)
+ #
+ # * bmp files have no native support for bmp files. We use a
+ # third party class to save as bmp.
+ {
- // *** Perform a check or two.
- if ( ! is_resource($this->imageResized))
- {
- if ($this->debug)
- {
- throw new Exception('saveImage: This is not a resource.');
- }
- else
- {
- throw new Exception();
- }
- }
- $fileInfoArray = pathInfo($savePath);
- clearstatcache();
- if ( ! is_writable($fileInfoArray['dirname']))
- {
- if ($this->debug)
- {
- throw new Exception('The path is not writable. Please check your permissions.');
- }
- else
- {
- throw new Exception();
- }
- }
+ // *** Perform a check or two.
+ if (! is_resource($this->imageResized) && ! $this->imageResized instanceof \GdImage)
+ {
+ if ($this->debug)
+ {
+ throw new Exception('saveImage: This is not a resource.');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ }
+ $fileInfoArray = pathInfo($savePath);
+ clearstatcache();
+ if ( ! is_writable($fileInfoArray['dirname']))
+ {
+ if ($this->debug)
+ {
+ throw new Exception('The path is not writable. Please check your permissions.');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ }
- // *** Get extension
- $extension = strrchr($savePath, '.');
- $extension = fix_strtolower($extension);
+ // *** Get extension
+ $extension = strrchr($savePath, '.');
+ $extension = fix_strtolower($extension);
- $error = '';
+ $error = '';
- switch ($extension)
- {
- case '.jpg':
- case '.jpeg':
- $this->checkInterlaceImage($this->isInterlace);
- if (imagetypes() & IMG_JPG)
- {
- imagejpeg($this->imageResized, $savePath, $imageQuality);
- }
- else
- {
- $error = 'jpg';
- }
- break;
+ switch ($extension)
+ {
+ case '.jpg':
+ case '.jpeg':
+ $this->checkInterlaceImage($this->isInterlace);
+ if (imagetypes() & IMG_JPG)
+ {
+ imagejpeg($this->imageResized, $savePath, $imageQuality);
+ }
+ else
+ {
+ $error = 'jpg';
+ }
+ break;
- case '.gif':
- $this->checkInterlaceImage($this->isInterlace);
- if (imagetypes() & IMG_GIF)
- {
- imagegif($this->imageResized, $savePath);
- }
- else
- {
- $error = 'gif';
- }
- break;
+ case '.webp':
+ if (imagetypes() & IMG_WEBP)
+ {
+ imagewebp($this->imageResized, $savePath, $imageQuality);
+ }
+ else
+ {
+ $error = 'webp';
+ }
+ break;
- case '.png':
- // *** Scale quality from 0-100 to 0-9
- $scaleQuality = round(($imageQuality / 100) * 9);
+ case '.gif':
+ $this->checkInterlaceImage($this->isInterlace);
+ if (imagetypes() & IMG_GIF)
+ {
+ imagegif($this->imageResized, $savePath);
+ }
+ else
+ {
+ $error = 'gif';
+ }
+ break;
- // *** Invert qualit setting as 0 is best, not 9
- $invertScaleQuality = 9 - $scaleQuality;
+ case '.png':
+ // *** Scale quality from 0-100 to 0-9
+ $scaleQuality = round(($imageQuality / 100) * 9);
- $this->checkInterlaceImage($this->isInterlace);
- if (imagetypes() & IMG_PNG)
- {
- imagepng($this->imageResized, $savePath, $invertScaleQuality);
- }
- else
- {
- $error = 'png';
- }
- break;
+ // *** Invert qualit setting as 0 is best, not 9
+ $invertScaleQuality = 9 - $scaleQuality;
- case '.bmp':
- file_put_contents($savePath, $this->GD2BMPstring($this->imageResized));
- break;
+ $this->checkInterlaceImage($this->isInterlace);
+ if (imagetypes() & IMG_PNG)
+ {
+ imagepng($this->imageResized, $savePath, $invertScaleQuality);
+ }
+ else
+ {
+ $error = 'png';
+ }
+ break;
+
+ case '.bmp':
+ file_put_contents($savePath, $this->GD2BMPstring($this->imageResized));
+ break;
- // ... etc
+ // ... etc
- default:
- // *** No extension - No save.
- $this->errorArray[] = 'This file type (' . $extension . ') is not supported. File not saved.';
- break;
- }
+ default:
+ // *** No extension - No save.
+ $this->errorArray[] = 'This file type (' . $extension . ') is not supported. File not saved.';
+ break;
+ }
- //imagedestroy($this->imageResized);
+ //imagedestroy($this->imageResized);
- // *** Display error if a file type is not supported.
- if ($error != '')
- {
- $this->errorArray[] = $error . ' support is NOT enabled. File not saved.';
- }
- }
+ // *** Display error if a file type is not supported.
+ if ($error != '')
+ {
+ $this->errorArray[] = $error . ' support is NOT enabled. File not saved.';
+ }
+ }
## --------------------------------------------------------
- public function displayImage($fileType = 'jpg', $imageQuality = "100")
- # Author: Jarrod Oberto
- # Date: 18-11-09
- # Purpose: Display images directly to the browser
- # Param in: The image type you want to display
- # Param out:
- # Reference:
- # Notes:
- #
- {
+ public function displayImage($fileType = 'jpg', $imageQuality = "100")
+ # Author: Jarrod Oberto
+ # Date: 18-11-09
+ # Purpose: Display images directly to the browser
+ # Param in: The image type you want to display
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
- if ( ! is_resource($this->imageResized))
- {
- if ($this->debug)
- {
- throw new Exception('saveImage: This is not a resource.');
- }
- else
- {
- throw new Exception();
- }
- }
+ if (! is_resource($this->imageResized) && ! $this->imageResized instanceof \GdImage)
+ {
+ if ($this->debug)
+ {
+ throw new Exception('saveImage: This is not a resource.');
+ }
+ else
+ {
+ throw new Exception();
+ }
+ }
- switch ($fileType)
- {
- case 'jpg':
- case 'jpeg':
- header('Content-type: image/jpeg');
- imagejpeg($this->imageResized, '', $imageQuality);
- break;
- case 'gif':
- header('Content-type: image/gif');
- imagegif($this->imageResized);
- break;
- case 'png':
- header('Content-type: image/png');
+ switch ($fileType)
+ {
+ case 'jpg':
+ case 'jpeg':
+ header('Content-type: image/jpeg');
+ imagejpeg($this->imageResized, '', $imageQuality);
+ break;
+ case 'webp':
+ header('Content-type: image/webp');
+ imagewebp($this->imageResized, '', $imageQuality);
+ break;
+ case 'gif':
+ header('Content-type: image/gif');
+ imagegif($this->imageResized);
+ break;
+ case 'png':
+ header('Content-type: image/png');
- // *** Scale quality from 0-100 to 0-9
- $scaleQuality = round(($imageQuality / 100) * 9);
+ // *** Scale quality from 0-100 to 0-9
+ $scaleQuality = round(($imageQuality / 100) * 9);
- // *** Invert qualit setting as 0 is best, not 9
- $invertScaleQuality = 9 - $scaleQuality;
+ // *** Invert qualit setting as 0 is best, not 9
+ $invertScaleQuality = 9 - $scaleQuality;
- imagepng($this->imageResized, '', $invertScaleQuality);
- break;
- case 'bmp':
- echo 'bmp file format is not supported.';
- break;
+ imagepng($this->imageResized, '', $invertScaleQuality);
+ break;
+ case 'bmp':
+ echo 'bmp file format is not supported.';
+ break;
- // ... etc
+ // ... etc
- default:
- // *** No extension - No save.
- break;
- }
+ default:
+ // *** No extension - No save.
+ break;
+ }
- //imagedestroy($this->imageResized);
- }
+ //imagedestroy($this->imageResized);
+ }
## --------------------------------------------------------
- public function setTransparency($bool)
- # Sep 2011
- {
- $this->keepTransparency = $bool;
- }
+ public function setTransparency($bool)
+ # Sep 2011
+ {
+ $this->keepTransparency = $bool;
+ }
## --------------------------------------------------------
- public function setFillColor($value)
- # Sep 2011
- # Param in: (mixed) $value: (array) Could be an array of RGB
- # (str) Could be hex #ffffff or #fff, fff, ffffff
- #
- # If the keepTransparency is set to false, then no transparency is to be used.
- # This is ideal when you want to save as jpg.
- #
- # this method allows you to set the background color to use instead of
- # transparency.
- #
- {
- $colorArray = $this->formatColor($value);
- $this->fillColorArray = $colorArray;
- }
+ public function setFillColor($value)
+ # Sep 2011
+ # Param in: (mixed) $value: (array) Could be an array of RGB
+ # (str) Could be hex #ffffff or #fff, fff, ffffff
+ #
+ # If the keepTransparency is set to false, then no transparency is to be used.
+ # This is ideal when you want to save as jpg.
+ #
+ # this method allows you to set the background color to use instead of
+ # transparency.
+ #
+ {
+ $colorArray = $this->formatColor($value);
+ $this->fillColorArray = $colorArray;
+ }
## --------------------------------------------------------
- public function setCropFromTop($value)
- # Sep 2011
- {
- $this->cropFromTopPercent = $value;
- }
+ public function setCropFromTop($value)
+ # Sep 2011
+ {
+ $this->cropFromTopPercent = $value;
+ }
## --------------------------------------------------------
- public function testGDInstalled()
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose: Test to see if GD is installed
- # Param in: n/a
- # Param out: (bool) True is gd extension loaded otherwise false
- # Reference:
- # Notes:
- #
- {
- if (extension_loaded('gd') && function_exists('gd_info'))
- {
- $gdInstalled = true;
- }
- else
- {
- $gdInstalled = false;
- }
+ public function testGDInstalled()
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose: Test to see if GD is installed
+ # Param in: n/a
+ # Param out: (bool) True is gd extension loaded otherwise false
+ # Reference:
+ # Notes:
+ #
+ {
+ if (extension_loaded('gd') && function_exists('gd_info'))
+ {
+ $gdInstalled = true;
+ }
+ else
+ {
+ $gdInstalled = false;
+ }
- return $gdInstalled;
- }
+ return $gdInstalled;
+ }
## --------------------------------------------------------
- public function testEXIFInstalled()
- # Author: Jarrod Oberto
- # Date: 08-05-11
- # Purpose: Test to see if EXIF is installed
- # Param in: n/a
- # Param out: (bool) True is exif extension loaded otherwise false
- # Reference:
- # Notes:
- #
- {
- if (extension_loaded('exif'))
- {
- $exifInstalled = true;
- }
- else
- {
- $exifInstalled = false;
- }
+ public function testEXIFInstalled()
+ # Author: Jarrod Oberto
+ # Date: 08-05-11
+ # Purpose: Test to see if EXIF is installed
+ # Param in: n/a
+ # Param out: (bool) True is exif extension loaded otherwise false
+ # Reference:
+ # Notes:
+ #
+ {
+ if (extension_loaded('exif'))
+ {
+ $exifInstalled = true;
+ }
+ else
+ {
+ $exifInstalled = false;
+ }
- return $exifInstalled;
- }
+ return $exifInstalled;
+ }
## --------------------------------------------------------
- public function testIsImage($image)
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose: Test if file is an image
- # Param in: n/a
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- if ($image)
- {
- $fileIsImage = true;
- }
- else
- {
- $fileIsImage = false;
- }
+ public function testIsImage($image)
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose: Test if file is an image
+ # Param in: n/a
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ if ($image)
+ {
+ $fileIsImage = true;
+ }
+ else
+ {
+ $fileIsImage = false;
+ }
- return $fileIsImage;
- }
+ return $fileIsImage;
+ }
## --------------------------------------------------------
- public function testFunct()
- # Author: Jarrod Oberto
- # Date: 27-02-08
- # Purpose: Test Function
- # Param in: n/a
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- echo $this->height;
- }
+ public function testFunct()
+ # Author: Jarrod Oberto
+ # Date: 27-02-08
+ # Purpose: Test Function
+ # Param in: n/a
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ echo $this->height;
+ }
## --------------------------------------------------------
- public function setForceStretch($value)
- # Author: Jarrod Oberto
- # Date: 23-12-10
- # Purpose:
- # Param in: (bool) $value
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- $this->forceStretch = $value;
- }
+ public function setForceStretch($value)
+ # Author: Jarrod Oberto
+ # Date: 23-12-10
+ # Purpose:
+ # Param in: (bool) $value
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ $this->forceStretch = $value;
+ }
## --------------------------------------------------------
- public function setFile($fileName)
- # Author: Jarrod Oberto
- # Date: 28-02-08
- # Purpose:
- # Param in: n/a
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- self::__construct($fileName);
- }
+ public function setFile($fileName)
+ # Author: Jarrod Oberto
+ # Date: 28-02-08
+ # Purpose:
+ # Param in: n/a
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ self::__construct($fileName);
+ }
## --------------------------------------------------------
- public function getFileName()
- # Author: Jarrod Oberto
- # Date: 10-09-08
- # Purpose:
- # Param in: n/a
- # Param out: n/a
- # Reference:
- # Notes:
- #
- {
- return $this->fileName;
- }
+ public function getFileName()
+ # Author: Jarrod Oberto
+ # Date: 10-09-08
+ # Purpose:
+ # Param in: n/a
+ # Param out: n/a
+ # Reference:
+ # Notes:
+ #
+ {
+ return $this->fileName;
+ }
## --------------------------------------------------------
- public function getHeight()
- {
- return $this->height;
- }
+ public function getHeight()
+ {
+ return $this->height;
+ }
## --------------------------------------------------------
- public function getWidth()
- {
- return $this->width;
- }
+ public function getWidth()
+ {
+ return $this->width;
+ }
## --------------------------------------------------------
- public function getOriginalHeight()
- {
- return $this->heightOriginal;
- }
+ public function getOriginalHeight()
+ {
+ return $this->heightOriginal;
+ }
## --------------------------------------------------------
- public function getOriginalWidth()
- {
- return $this->widthOriginal;
- }
+ public function getOriginalWidth()
+ {
+ return $this->widthOriginal;
+ }
## --------------------------------------------------------
- public function getErrors()
- # Author: Jarrod Oberto
- # Date: 19-11-09
- # Purpose: Returns the error array
- # Param in: n/a
- # Param out: Array of errors
- # Reference:
- # Notes:
- #
- {
- return $this->errorArray;
- }
+ public function getErrors()
+ # Author: Jarrod Oberto
+ # Date: 19-11-09
+ # Purpose: Returns the error array
+ # Param in: n/a
+ # Param out: Array of errors
+ # Reference:
+ # Notes:
+ #
+ {
+ return $this->errorArray;
+ }
## --------------------------------------------------------
- private function checkInterlaceImage($isEnabled)
- # jpg will use progressive (they don't use interace)
- {
- if ($isEnabled)
- {
- imageinterlace($this->imageResized, $isEnabled);
- }
- }
+ private function checkInterlaceImage($isEnabled)
+ # jpg will use progressive (they don't use interace)
+ {
+ if ($isEnabled)
+ {
+ imageinterlace($this->imageResized, $isEnabled);
+ }
+ }
## --------------------------------------------------------
- protected function formatColor($value)
- # Author: Jarrod Oberto
- # Date: 09-05-11
- # Purpose: Determine color method passed in and return color as RGB
- # Param in: (mixed) $value: (array) Could be an array of RGB
- # (str) Could be hex #ffffff or #fff, fff, ffffff
- # Param out:
- # Reference:
- # Notes:
- #
- {
- $rgbArray = array();
+ protected function formatColor($value)
+ # Author: Jarrod Oberto
+ # Date: 09-05-11
+ # Purpose: Determine color method passed in and return color as RGB
+ # Param in: (mixed) $value: (array) Could be an array of RGB
+ # (str) Could be hex #ffffff or #fff, fff, ffffff
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ $rgbArray = array();
- // *** If it's an array it should be R, G, B
- if (is_array($value))
- {
+ // *** If it's an array it should be R, G, B
+ if (is_array($value))
+ {
- if (key($value) == 0 && count($value) == 3)
- {
+ if (key($value) == 0 && count($value) == 3)
+ {
- $rgbArray['r'] = $value[0];
- $rgbArray['g'] = $value[1];
- $rgbArray['b'] = $value[2];
+ $rgbArray['r'] = $value[0];
+ $rgbArray['g'] = $value[1];
+ $rgbArray['b'] = $value[2];
- }
- else
- {
- $rgbArray = $value;
- }
- }
- else
- {
- if (fix_strtolower($value) == 'transparent')
- {
+ }
+ else
+ {
+ $rgbArray = $value;
+ }
+ }
+ else
+ {
+ if (fix_strtolower($value) == 'transparent')
+ {
- $rgbArray = array(
- 'r' => 255,
- 'g' => 255,
- 'b' => 255,
- 'a' => 127
- );
+ $rgbArray = array(
+ 'r' => 255,
+ 'g' => 255,
+ 'b' => 255,
+ 'a' => 127
+ );
- }
- else
- {
+ }
+ else
+ {
- // *** ...Else it should be hex. Let's make it RGB
- $rgbArray = $this->hex2dec($value);
- }
- }
+ // *** ...Else it should be hex. Let's make it RGB
+ $rgbArray = $this->hex2dec($value);
+ }
+ }
- return $rgbArray;
- }
+ return $rgbArray;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- function hex2dec($hex)
- # Purpose: Convert #hex color to RGB
- {
- $color = str_replace('#', '', $hex);
+ function hex2dec($hex)
+ # Purpose: Convert #hex color to RGB
+ {
+ $color = str_replace('#', '', $hex);
- if (strlen($color) == 3)
- {
- $color = $color . $color;
- }
+ if (strlen($color) == 3)
+ {
+ $color = $color . $color;
+ }
- $rgb = array(
- 'r' => hexdec(substr($color, 0, 2)),
- 'g' => hexdec(substr($color, 2, 2)),
- 'b' => hexdec(substr($color, 4, 2)),
- 'a' => 0
- );
+ $rgb = array(
+ 'r' => hexdec(substr($color, 0, 2)),
+ 'g' => hexdec(substr($color, 2, 2)),
+ 'b' => hexdec(substr($color, 4, 2)),
+ 'a' => 0
+ );
- return $rgb;
- }
+ return $rgb;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function createImageColor($colorArray)
- {
- $r = $colorArray['r'];
- $g = $colorArray['g'];
- $b = $colorArray['b'];
+ private function createImageColor($colorArray)
+ {
+ $r = $colorArray['r'];
+ $g = $colorArray['g'];
+ $b = $colorArray['b'];
- return imagecolorallocate($this->imageResized, $r, $g, $b);
- }
+ return imagecolorallocate($this->imageResized, $r, $g, $b);
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function testColorExists($colorArray)
- {
- $r = $colorArray['r'];
- $g = $colorArray['g'];
- $b = $colorArray['b'];
+ private function testColorExists($colorArray)
+ {
+ $r = $colorArray['r'];
+ $g = $colorArray['g'];
+ $b = $colorArray['b'];
- if (imagecolorexact($this->imageResized, $r, $g, $b) == -1)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
+ if (imagecolorexact($this->imageResized, $r, $g, $b) == -1)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function findUnusedGreen()
- # Purpose: We find a green color suitable to use like green-screen effect.
- # Therefore, the color must not exist in the image.
- {
- $green = 255;
+ private function findUnusedGreen()
+ # Purpose: We find a green color suitable to use like green-screen effect.
+ # Therefore, the color must not exist in the image.
+ {
+ $green = 255;
- do
- {
+ do
+ {
- $greenChroma = array( 0, $green, 0 );
- $colorArray = $this->formatColor($greenChroma);
- $match = $this->testColorExists($colorArray);
- $green--;
+ $greenChroma = array( 0, $green, 0 );
+ $colorArray = $this->formatColor($greenChroma);
+ $match = $this->testColorExists($colorArray);
+ $green--;
- } while ($match == false && $green > 0);
+ } while ($match == false && $green > 0);
- // *** If no match, just bite the bullet and use green value of 255
- if ( ! $match)
- {
- $greenChroma = array( 0, $green, 0 );
- }
+ // *** If no match, just bite the bullet and use green value of 255
+ if ( ! $match)
+ {
+ $greenChroma = array( 0, $green, 0 );
+ }
- return $greenChroma;
- }
+ return $greenChroma;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function findUnusedBlue()
- # Purpose: We find a green color suitable to use like green-screen effect.
- # Therefore, the color must not exist in the image.
- {
- $blue = 255;
+ private function findUnusedBlue()
+ # Purpose: We find a green color suitable to use like green-screen effect.
+ # Therefore, the color must not exist in the image.
+ {
+ $blue = 255;
- do
- {
+ do
+ {
- $blueChroma = array( 0, 0, $blue );
- $colorArray = $this->formatColor($blueChroma);
- $match = $this->testColorExists($colorArray);
- $blue--;
+ $blueChroma = array( 0, 0, $blue );
+ $colorArray = $this->formatColor($blueChroma);
+ $match = $this->testColorExists($colorArray);
+ $blue--;
- } while ($match == false && $blue > 0);
+ } while ($match == false && $blue > 0);
- // *** If no match, just bite the bullet and use blue value of 255
- if ( ! $match)
- {
- $blueChroma = array( 0, 0, $blue );
- }
+ // *** If no match, just bite the bullet and use blue value of 255
+ if ( ! $match)
+ {
+ $blueChroma = array( 0, 0, $blue );
+ }
- return $blueChroma;
- }
+ return $blueChroma;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function invertTransparency($value, $originalMax, $invert = true)
- # Purpose: This does two things:
- # 1) Convert the range from 0-127 to 0-100
- # 2) Inverts value to 100 is not transparent while 0 is fully
- # transparent (like Photoshop)
- {
- // *** Test max range
- if ($value > $originalMax)
- {
- $value = $originalMax;
- }
+ private function invertTransparency($value, $originalMax, $invert = true)
+ # Purpose: This does two things:
+ # 1) Convert the range from 0-127 to 0-100
+ # 2) Inverts value to 100 is not transparent while 0 is fully
+ # transparent (like Photoshop)
+ {
+ // *** Test max range
+ if ($value > $originalMax)
+ {
+ $value = $originalMax;
+ }
- // *** Test min range
- if ($value < 0)
- {
- $value = 0;
- }
+ // *** Test min range
+ if ($value < 0)
+ {
+ $value = 0;
+ }
- if ($invert)
- {
- return $originalMax - (($value / 100) * $originalMax);
- }
- else
- {
- return ($value / 100) * $originalMax;
- }
- }
+ if ($invert)
+ {
+ return $originalMax - (($value / 100) * $originalMax);
+ }
+ else
+ {
+ return ($value / 100) * $originalMax;
+ }
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- private function transparentImage($src)
- {
- // *** making images with white bg transparent
- $r1 = 0;
- $g1 = 255;
- $b1 = 0;
- for ($x = 0; $x < imagesx($src); ++$x)
- {
- for ($y = 0; $y < imagesy($src); ++$y)
- {
- $color = imagecolorat($src, $x, $y);
- $r = ($color >> 16) & 0xFF;
- $g = ($color >> 8) & 0xFF;
- $b = $color & 0xFF;
- for ($i = 0; $i < 270; $i++)
- {
- //if ($r . $g . $b == ($r1 + $i) . ($g1 + $i) . ($b1 + $i)) {
- if ($r == 0 && $g == 255 && $b == 0)
- {
- //if ($g == 255) {
- $trans_colour = imagecolorallocatealpha($src, 0, 0, 0, 127);
- imagefill($src, $x, $y, $trans_colour);
- }
- }
- }
- }
+ private function transparentImage($src)
+ {
+ // *** making images with white bg transparent
+ $r1 = 0;
+ $g1 = 255;
+ $b1 = 0;
+ for ($x = 0; $x < imagesx($src); ++$x)
+ {
+ for ($y = 0; $y < imagesy($src); ++$y)
+ {
+ $color = imagecolorat($src, $x, $y);
+ $r = ($color >> 16) & 0xFF;
+ $g = ($color >> 8) & 0xFF;
+ $b = $color & 0xFF;
+ for ($i = 0; $i < 270; $i++)
+ {
+ //if ($r . $g . $b == ($r1 + $i) . ($g1 + $i) . ($b1 + $i)) {
+ if ($r == 0 && $g == 255 && $b == 0)
+ {
+ //if ($g == 255) {
+ $trans_colour = imagecolorallocatealpha($src, 0, 0, 0, 127);
+ imagefill($src, $x, $y, $trans_colour);
+ }
+ }
+ }
+ }
- return $src;
- }
+ return $src;
+ }
- ## --------------------------------------------------------
+ ## --------------------------------------------------------
- function checkStringStartsWith($needle, $haystack)
- # Check if a string starts with a specific pattern
- {
- return (substr($haystack, 0, strlen($needle)) == $needle);
- }
+ function checkStringStartsWith($needle, $haystack)
+ # Check if a string starts with a specific pattern
+ {
+ return (substr($haystack, 0, strlen($needle)) == $needle);
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
BMP SUPPORT (SAVING) - James Heinrich
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- private function GD2BMPstring(&$gd_image)
- # Author: James Heinrich
- # Purpose: Save file as type bmp
- # Param in: The image canvas (passed as ref)
- # Param out:
- # Reference:
- # Notes: This code was stripped out of two external files
- # (phpthumb.bmp.php,phpthumb.functions.php) and added below to
- # avoid dependancies.
- #
- {
- $imageX = ImageSX($gd_image);
- $imageY = ImageSY($gd_image);
+ private function GD2BMPstring(&$gd_image)
+ # Author: James Heinrich
+ # Purpose: Save file as type bmp
+ # Param in: The image canvas (passed as ref)
+ # Param out:
+ # Reference:
+ # Notes: This code was stripped out of two external files
+ # (phpthumb.bmp.php,phpthumb.functions.php) and added below to
+ # avoid dependancies.
+ #
+ {
+ $imageX = ImageSX($gd_image);
+ $imageY = ImageSY($gd_image);
- $BMP = '';
- for ($y = ($imageY - 1); $y >= 0; $y--)
- {
- $thisline = '';
- for ($x = 0; $x < $imageX; $x++)
- {
- $argb = $this->GetPixelColor($gd_image, $x, $y);
- $thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
- }
- while (strlen($thisline) % 4)
- {
- $thisline .= "\x00";
- }
- $BMP .= $thisline;
- }
+ $BMP = '';
+ for ($y = ($imageY - 1); $y >= 0; $y--)
+ {
+ $thisline = '';
+ for ($x = 0; $x < $imageX; $x++)
+ {
+ $argb = $this->GetPixelColor($gd_image, $x, $y);
+ $thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
+ }
+ while (strlen($thisline) % 4)
+ {
+ $thisline .= "\x00";
+ }
+ $BMP .= $thisline;
+ }
- $bmpSize = strlen($BMP) + 14 + 40;
- // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
- $BITMAPFILEHEADER = 'BM'; // WORD bfType;
- $BITMAPFILEHEADER .= $this->LittleEndian2String($bmpSize, 4); // DWORD bfSize;
- $BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD bfReserved1;
- $BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD bfReserved2;
- $BITMAPFILEHEADER .= $this->LittleEndian2String(54, 4); // DWORD bfOffBits;
+ $bmpSize = strlen($BMP) + 14 + 40;
+ // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
+ $BITMAPFILEHEADER = 'BM'; // WORD bfType;
+ $BITMAPFILEHEADER .= $this->LittleEndian2String($bmpSize, 4); // DWORD bfSize;
+ $BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD bfReserved1;
+ $BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD bfReserved2;
+ $BITMAPFILEHEADER .= $this->LittleEndian2String(54, 4); // DWORD bfOffBits;
- // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
- $BITMAPINFOHEADER = $this->LittleEndian2String(40, 4); // DWORD biSize;
- $BITMAPINFOHEADER .= $this->LittleEndian2String($imageX, 4); // LONG biWidth;
- $BITMAPINFOHEADER .= $this->LittleEndian2String($imageY, 4); // LONG biHeight;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(1, 2); // WORD biPlanes;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(24, 2); // WORD biBitCount;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biCompression;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biSizeImage;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG biXPelsPerMeter;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG biYPelsPerMeter;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biClrUsed;
- $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biClrImportant;
+ // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
+ $BITMAPINFOHEADER = $this->LittleEndian2String(40, 4); // DWORD biSize;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String($imageX, 4); // LONG biWidth;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String($imageY, 4); // LONG biHeight;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(1, 2); // WORD biPlanes;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(24, 2); // WORD biBitCount;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biCompression;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biSizeImage;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG biXPelsPerMeter;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG biYPelsPerMeter;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biClrUsed;
+ $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD biClrImportant;
- return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
- }
+ return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
+ }
## --------------------------------------------------------
- private function GetPixelColor(&$img, $x, $y)
- # Author: James Heinrich
- # Purpose:
- # Param in:
- # Param out:
- # Reference:
- # Notes:
- #
- {
- if ( ! is_resource($img))
- {
- return false;
- }
+ private function GetPixelColor(&$img, $x, $y)
+ # Author: James Heinrich
+ # Purpose:
+ # Param in:
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ if (! is_resource($img) && ! $img instanceof \GdImage)
+ {
+ return false;
+ }
- return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
- }
+ return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
+ }
## --------------------------------------------------------
- private function LittleEndian2String($number, $minbytes = 1)
- # Author: James Heinrich
- # Purpose: BMP SUPPORT (SAVING)
- # Param in:
- # Param out:
- # Reference:
- # Notes:
- #
- {
- $intstring = '';
- while ($number > 0)
- {
- $intstring = $intstring . chr($number & 255);
- $number >>= 8;
- }
+ private function LittleEndian2String($number, $minbytes = 1)
+ # Author: James Heinrich
+ # Purpose: BMP SUPPORT (SAVING)
+ # Param in:
+ # Param out:
+ # Reference:
+ # Notes:
+ #
+ {
+ $intstring = '';
+ while ($number > 0)
+ {
+ $intstring = $intstring . chr($number & 255);
+ $number >>= 8;
+ }
- return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
- }
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
BMP SUPPORT (READING)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- private function ImageCreateFromBMP($filename)
- # Author: DHKold
- # Date: The 15th of June 2005
- # Version: 2.0B
- # Purpose: To create an image from a BMP file.
- # Param in: BMP file to open.
- # Param out: Return a resource like the other ImageCreateFrom functions
- # Reference: http://us3.php.net/manual/en/function.imagecreate.php#53879
- # Bug fix: Author: domelca at terra dot es
- # Date: 06 March 2008
- # Fix: Correct 16bit BMP support
- # Notes:
- #
- {
+ private function ImageCreateFromBMP($filename)
+ # Author: DHKold
+ # Date: The 15th of June 2005
+ # Version: 2.0B
+ # Purpose: To create an image from a BMP file.
+ # Param in: BMP file to open.
+ # Param out: Return a resource like the other ImageCreateFrom functions
+ # Reference: http://us3.php.net/manual/en/function.imagecreate.php#53879
+ # Bug fix: Author: domelca at terra dot es
+ # Date: 06 March 2008
+ # Fix: Correct 16bit BMP support
+ # Notes:
+ #
+ {
- //Ouverture du fichier en mode binaire
- if ( ! $f1 = fopen($filename, "rb"))
- {
- return false;
- }
+ //Ouverture du fichier en mode binaire
+ if ( ! $f1 = fopen($filename, "rb"))
+ {
+ return false;
+ }
- //1 : Chargement des ent�tes FICHIER
- $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
- if ($FILE['file_type'] != 19778)
- {
- return false;
- }
+ //1 : Chargement des ent�tes FICHIER
+ $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
+ if ($FILE['file_type'] != 19778)
+ {
+ return false;
+ }
- //2 : Chargement des ent�tes BMP
- $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' .
- '/Vcompression/Vsize_bitmap/Vhoriz_resolution' .
- '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
- $BMP['colors'] = pow(2, $BMP['bits_per_pixel']);
+ //2 : Chargement des ent�tes BMP
+ $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' .
+ '/Vcompression/Vsize_bitmap/Vhoriz_resolution' .
+ '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
+ $BMP['colors'] = pow(2, $BMP['bits_per_pixel']);
- if ($BMP['size_bitmap'] == 0)
- {
- $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
- }
+ if ($BMP['size_bitmap'] == 0)
+ {
+ $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
+ }
- $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
- $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
- $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
- $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
- $BMP['decal'] = 4 - (4 * $BMP['decal']);
+ $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
+ $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
+ $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
+ $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
+ $BMP['decal'] = 4 - (4 * $BMP['decal']);
- if ($BMP['decal'] == 4)
- {
- $BMP['decal'] = 0;
- }
+ if ($BMP['decal'] == 4)
+ {
+ $BMP['decal'] = 0;
+ }
- //3 : Chargement des couleurs de la palette
- $PALETTE = array();
- if ($BMP['colors'] < 16777216)
- {
- $PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4));
- }
+ //3 : Chargement des couleurs de la palette
+ $PALETTE = array();
+ if ($BMP['colors'] < 16777216)
+ {
+ $PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4));
+ }
- //4 : Cr�ation de l'image
- $IMG = fread($f1, $BMP['size_bitmap']);
- $VIDE = chr(0);
+ //4 : Cr�ation de l'image
+ $IMG = fread($f1, $BMP['size_bitmap']);
+ $VIDE = chr(0);
- $res = imagecreatetruecolor($BMP['width'], $BMP['height']);
- $P = 0;
- $Y = $BMP['height'] - 1;
- while ($Y >= 0)
- {
- $X = 0;
- while ($X < $BMP['width'])
- {
- if ($BMP['bits_per_pixel'] == 24)
- {
- $COLOR = unpack("V", substr($IMG, $P, 3) . $VIDE);
- }
- elseif ($BMP['bits_per_pixel'] == 16)
- {
+ $res = imagecreatetruecolor($BMP['width'], $BMP['height']);
+ $P = 0;
+ $Y = $BMP['height'] - 1;
+ while ($Y >= 0)
+ {
+ $X = 0;
+ while ($X < $BMP['width'])
+ {
+ if ($BMP['bits_per_pixel'] == 24)
+ {
+ $COLOR = unpack("V", substr($IMG, $P, 3) . $VIDE);
+ }
+ elseif ($BMP['bits_per_pixel'] == 16)
+ {
- /*
+ /*
* BMP 16bit fix
* =================
*
@@ -3591,138 +3610,138 @@ class imageLib {
*
*/
- // *** Original code (don't work)
- //$COLOR = unpack("n",substr($IMG,$P,2));
- //$COLOR[1] = $PALETTE[$COLOR[1]+1];
+ // *** Original code (don't work)
+ //$COLOR = unpack("n",substr($IMG,$P,2));
+ //$COLOR[1] = $PALETTE[$COLOR[1]+1];
- $COLOR = unpack("v", substr($IMG, $P, 2));
- $blue = ($COLOR[1] & 0x001f) << 3;
- $green = ($COLOR[1] & 0x07e0) >> 3;
- $red = ($COLOR[1] & 0xf800) >> 8;
- $COLOR[1] = $red * 65536 + $green * 256 + $blue;
+ $COLOR = unpack("v", substr($IMG, $P, 2));
+ $blue = ($COLOR[1] & 0x001f) << 3;
+ $green = ($COLOR[1] & 0x07e0) >> 3;
+ $red = ($COLOR[1] & 0xf800) >> 8;
+ $COLOR[1] = $red * 65536 + $green * 256 + $blue;
- }
- elseif ($BMP['bits_per_pixel'] == 8)
- {
- $COLOR = unpack("n", $VIDE . substr($IMG, $P, 1));
- $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
- }
- elseif ($BMP['bits_per_pixel'] == 4)
- {
- $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
- if (($P * 2) % 2 == 0)
- {
- $COLOR[1] = ($COLOR[1] >> 4);
- }
- else
- {
- $COLOR[1] = ($COLOR[1] & 0x0F);
- }
- $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
- }
- elseif ($BMP['bits_per_pixel'] == 1)
- {
- $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
- if (($P * 8) % 8 == 0)
- {
- $COLOR[1] = $COLOR[1] >> 7;
- }
- elseif (($P * 8) % 8 == 1)
- {
- $COLOR[1] = ($COLOR[1] & 0x40) >> 6;
- }
- elseif (($P * 8) % 8 == 2)
- {
- $COLOR[1] = ($COLOR[1] & 0x20) >> 5;
- }
- elseif (($P * 8) % 8 == 3)
- {
- $COLOR[1] = ($COLOR[1] & 0x10) >> 4;
- }
- elseif (($P * 8) % 8 == 4)
- {
- $COLOR[1] = ($COLOR[1] & 0x8) >> 3;
- }
- elseif (($P * 8) % 8 == 5)
- {
- $COLOR[1] = ($COLOR[1] & 0x4) >> 2;
- }
- elseif (($P * 8) % 8 == 6)
- {
- $COLOR[1] = ($COLOR[1] & 0x2) >> 1;
- }
- elseif (($P * 8) % 8 == 7)
- {
- $COLOR[1] = ($COLOR[1] & 0x1);
- }
- $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
- }
- else
- {
- return false;
- }
+ }
+ elseif ($BMP['bits_per_pixel'] == 8)
+ {
+ $COLOR = unpack("n", $VIDE . substr($IMG, $P, 1));
+ $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
+ }
+ elseif ($BMP['bits_per_pixel'] == 4)
+ {
+ $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
+ if (($P * 2) % 2 == 0)
+ {
+ $COLOR[1] = ($COLOR[1] >> 4);
+ }
+ else
+ {
+ $COLOR[1] = ($COLOR[1] & 0x0F);
+ }
+ $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
+ }
+ elseif ($BMP['bits_per_pixel'] == 1)
+ {
+ $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
+ if (($P * 8) % 8 == 0)
+ {
+ $COLOR[1] = $COLOR[1] >> 7;
+ }
+ elseif (($P * 8) % 8 == 1)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x40) >> 6;
+ }
+ elseif (($P * 8) % 8 == 2)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x20) >> 5;
+ }
+ elseif (($P * 8) % 8 == 3)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x10) >> 4;
+ }
+ elseif (($P * 8) % 8 == 4)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x8) >> 3;
+ }
+ elseif (($P * 8) % 8 == 5)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x4) >> 2;
+ }
+ elseif (($P * 8) % 8 == 6)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x2) >> 1;
+ }
+ elseif (($P * 8) % 8 == 7)
+ {
+ $COLOR[1] = ($COLOR[1] & 0x1);
+ }
+ $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
+ }
+ else
+ {
+ return false;
+ }
- imagesetpixel($res, $X, $Y, $COLOR[1]);
- $X++;
- $P += $BMP['bytes_per_pixel'];
- }
+ imagesetpixel($res, $X, $Y, $COLOR[1]);
+ $X++;
+ $P += $BMP['bytes_per_pixel'];
+ }
- $Y--;
- $P += $BMP['decal'];
- }
- //Fermeture du fichier
- fclose($f1);
+ $Y--;
+ $P += $BMP['decal'];
+ }
+ //Fermeture du fichier
+ fclose($f1);
- return $res;
- }
+ return $res;
+ }
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
PSD SUPPORT (READING)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/
- private function imagecreatefrompsd($fileName)
- # Author: Tim de Koning
- # Version: 1.3
- # Purpose: To create an image from a PSD file.
- # Param in: PSD file to open.
- # Param out: Return a resource like the other ImageCreateFrom functions
- # Reference: http://www.kingsquare.nl/phppsdreader
- # Notes:
- #
- {
- if (file_exists($this->psdReaderPath))
- {
+ private function imagecreatefrompsd($fileName)
+ # Author: Tim de Koning
+ # Version: 1.3
+ # Purpose: To create an image from a PSD file.
+ # Param in: PSD file to open.
+ # Param out: Return a resource like the other ImageCreateFrom functions
+ # Reference: http://www.kingsquare.nl/phppsdreader
+ # Notes:
+ #
+ {
+ if (file_exists($this->psdReaderPath))
+ {
- include_once($this->psdReaderPath);
+ include_once($this->psdReaderPath);
- $psdReader = new PhpPsdReader($fileName);
+ $psdReader = new PhpPsdReader($fileName);
- if (isset($psdReader->infoArray['error']))
- {
- return '';
- }
- else
- {
- return $psdReader->getImage();
- }
- }
- else
- {
- return false;
- }
- }
+ if (isset($psdReader->infoArray['error']))
+ {
+ return '';
+ }
+ else
+ {
+ return $psdReader->getImage();
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
## --------------------------------------------------------
- public function __destruct()
- {
- if (is_resource($this->imageResized))
- {
- imagedestroy($this->imageResized);
- }
- }
+ public function __destruct()
+ {
+ if (is_resource($this->imageResized) || $this->imageResized instanceof \GdImage)
+ {
+ imagedestroy($this->imageResized);
+ }
+ }
## --------------------------------------------------------
diff --git a/core/vendor/filemanager/include/utils.php b/core/vendor/filemanager/include/utils.php
index 8cda9602..9275eaaf 100644
--- a/core/vendor/filemanager/include/utils.php
+++ b/core/vendor/filemanager/include/utils.php
@@ -1,1345 +1,1315 @@
send();
- exit;
- }
-
- }
- if(file_exists('lang/' . $lang . '.php')){
- $lang_vars = include 'lang/' . $lang . '.php';
- }else{
- $lang_vars = include '../lang/' . $lang . '.php';
- }
-
- if ( ! is_array($lang_vars))
- {
- $lang_vars = array();
- }
+ return new $responseClass($content, $statusCode, $headers);
+ }
}
+if (!function_exists('trans')) {
+ /**
+ * Translate language variable
+ *
+ * @param $var string name
+ *
+ * @return string translated variable
+ */
+ function trans($var)
+ {
+ global $lang_vars;
-function checkRelativePathPartial($path){
- if (strpos($path, '../') !== false
+ return (array_key_exists($var, $lang_vars)) ? $lang_vars[$var] : $var;
+ }
+
+ // language
+ if (!isset($_SESSION['RF']['language'])
+ || file_exists('lang/' . basename($_SESSION['RF']['language']) . '.php') === false
+ || !is_readable('lang/' . basename($_SESSION['RF']['language']) . '.php')
+ ) {
+ $lang = $config['default_language'];
+
+ if (isset($_GET['lang']) && $_GET['lang'] != 'undefined' && $_GET['lang'] != '') {
+ $lang = fix_get_params($_GET['lang']);
+ $lang = trim($lang);
+ }
+
+ if ($lang != $config['default_language']) {
+ $path_parts = pathinfo($lang);
+ $lang = $path_parts['basename'];
+ $languages = include 'lang/languages.php';
+ }
+
+ // add lang file to session for easy include
+ $_SESSION['RF']['language'] = $lang;
+ } else {
+ if (file_exists('lang/languages.php')) {
+ $languages = include 'lang/languages.php';
+ } else {
+ $languages = include '../lang/languages.php';
+ }
+
+ if (array_key_exists($_SESSION['RF']['language'], $languages)) {
+ $lang = $_SESSION['RF']['language'];
+ } else {
+ response('Lang_Not_Found' . AddErrorLocation())->send();
+ exit;
+ }
+ }
+ if (file_exists('lang/' . $lang . '.php')) {
+ $lang_vars = include 'lang/' . $lang . '.php';
+ } else {
+ $lang_vars = include '../lang/' . $lang . '.php';
+ }
+
+ if (!is_array($lang_vars)) {
+ $lang_vars = array();
+ }
+}
+
+/**
+ * @param $path
+ * @return bool
+ */
+function checkRelativePathPartial($path)
+{
+ if (strpos($path, '../') !== false
|| strpos($path, './') !== false
|| strpos($path, '/..') !== false
|| strpos($path, '..\\') !== false
|| strpos($path, '\\..') !== false
|| strpos($path, '.\\') !== false
|| $path === ".."
- ){
- return false;
+ ) {
+ return false;
}
return true;
}
/**
-* Check relative path
-*
-* @param string $path
-*
-* @return boolean is it correct?
-*/
-function checkRelativePath($path){
- $path_correct = checkRelativePathPartial($path);
- if($path_correct){
- $path_decoded = rawurldecode($path);
- $path_correct = checkRelativePathPartial($path_decoded);
- }
+ * Check relative path
+ *
+ * @param string $path
+ *
+ * @return boolean is it correct?
+ */
+function checkRelativePath($path)
+{
+ $path_correct = checkRelativePathPartial($path);
+ if ($path_correct) {
+ $path_decoded = rawurldecode($path);
+ $path_correct = checkRelativePathPartial($path_decoded);
+ }
return $path_correct;
}
/**
-* Check if the given path is an upload dir based on config
-*
-* @param string $path
-* @param array $config
-*
-* @return boolean is it an upload dir?
-*/
-function isUploadDir($path, $config){
- $upload_dir = $config['current_path'];
- $thumbs_dir = $config['thumbs_base_path'];
- if (realpath($path) === realpath($upload_dir) || realpath($path) === realpath($thumbs_dir))
- {
- return true;
- }
- return false;
-}
-
-/**
-* Delete file
-*
-* @param string $path
-* @param string $path_thumb
-* @param array $config
-*
-* @return null
-*/
-function deleteFile($path,$path_thumb,$config){
- if ($config['delete_files']){
- $ftp = ftp_con($config);
- if($ftp){
- try{
- $ftp->delete("/".$path);
- @$ftp->delete("/".$path_thumb);
- }catch(FtpClient\FtpException $e){
- return;
- }
- }else{
- if (file_exists($path)){
- unlink($path);
- }
- if (file_exists($path_thumb)){
- unlink($path_thumb);
- }
- }
-
- $info=pathinfo($path);
- if (!$ftp && $config['relative_image_creation']){
- foreach($config['relative_path_from_current_pos'] as $k=>$path)
- {
- if ($path!="" && $path[strlen($path)-1]!="/") $path.="/";
-
- if (file_exists($info['dirname']."/".$path.$config['relative_image_creation_name_to_prepend'][$k].$info['filename'].$config['relative_image_creation_name_to_append'][$k].".".$info['extension']))
- {
- unlink($info['dirname']."/".$path.$config['relative_image_creation_name_to_prepend'][$k].$info['filename'].$config['relative_image_creation_name_to_append'][$k].".".$info['extension']);
- }
- }
- }
-
- if (!$ftp && $config['fixed_image_creation'])
- {
- foreach($config['fixed_path_from_filemanager'] as $k=>$path)
- {
- if ($path!="" && $path[strlen($path)-1] != "/") $path.="/";
-
- $base_dir=$path.substr_replace($info['dirname']."/", '', 0, strlen($config['current_path']));
- if (file_exists($base_dir.$config['fixed_image_creation_name_to_prepend'][$k].$info['filename'].$config['fixed_image_creation_to_append'][$k].".".$info['extension']))
- {
- unlink($base_dir.$config['fixed_image_creation_name_to_prepend'][$k].$info['filename'].$config['fixed_image_creation_to_append'][$k].".".$info['extension']);
- }
- }
- }
- }
-}
-
-/**
-* Delete directory
-*
-* @param string $dir
-*
-* @return bool
-*/
-function deleteDir($dir,$ftp = null, $config = null)
+ * Check if the given path is an upload dir based on config
+ *
+ * @param string $path
+ * @param array $config
+ *
+ * @return boolean is it an upload dir?
+ */
+function isUploadDir($path, $config)
{
- if($ftp){
-
- try{
- $ftp->rmdir($dir);
- return true;
-
- }catch(FtpClient\FtpException $e){
- return null;
- }
-
- }else{
- if ( ! file_exists($dir) || isUploadDir($dir, $config))
- {
- return false;
- }
- if ( ! is_dir($dir))
- {
- return unlink($dir);
- }
- foreach (scandir($dir) as $item)
- {
- if ($item == '.' || $item == '..')
- {
- continue;
- }
- if ( ! deleteDir($dir . DIRECTORY_SEPARATOR . $item))
- {
- return false;
- }
- }
- }
-
- return rmdir($dir);
+ $upload_dir = $config['current_path'];
+ $thumbs_dir = $config['thumbs_base_path'];
+ if (realpath($path) === realpath($upload_dir) || realpath($path) === realpath($thumbs_dir)) {
+ return true;
+ }
+ return false;
}
/**
-* Make a file copy
-*
-* @param string $old_path
-* @param string $name New file name without extension
-*
-* @return bool
-*/
-function duplicate_file( $old_path, $name, $ftp = null, $config = null )
+ * Delete file
+ *
+ * @param string $path
+ * @param string $path_thumb
+ * @param array $config
+ *
+ * @return null
+ */
+function deleteFile($path, $path_thumb, $config)
{
- $info = pathinfo($old_path);
- $new_path = $info['dirname'] . "/" . $name . "." . $info['extension'];
- if($ftp){
- try{
- $tmp = time().$name . "." . $info['extension'];
- $ftp->get($tmp, "/".$old_path, FTP_BINARY);
- $ftp->put("/".$new_path, $tmp, FTP_BINARY);
- unlink($tmp);
- return true;
+ if ($config['delete_files']) {
+ try {
+ $ftp = ftp_con($config);
+ } catch (\FtpClient\FtpException $e) {
+ return;
+ }
- }catch(FtpClient\FtpException $e){
- return null;
- }
- }else{
- if (file_exists($old_path) && is_file($old_path))
- {
- if (file_exists($new_path) && $old_path == $new_path)
- {
- return false;
- }
+ if ($ftp) {
+ $ftp->delete("/" . $path);
+ @$ftp->delete("/" . $path_thumb);
+ } else {
+ if (file_exists($path)) {
+ unlink($path);
+ }
+ if (file_exists($path_thumb)) {
+ unlink($path_thumb);
+ }
+ }
- return copy($old_path, $new_path);
- }
- }
+ $info = pathinfo($path);
+ if (!$ftp && $config['relative_image_creation']) {
+ foreach ($config['relative_path_from_current_pos'] as $k => $path) {
+ if ($path != "" && $path[strlen($path) - 1] != "/") {
+ $path .= "/";
+ }
+
+ if (file_exists(
+ $info['dirname'] . "/" . $path . $config['relative_image_creation_name_to_prepend'][$k] . $info['filename'] . $config['relative_image_creation_name_to_append'][$k] . "." . $info['extension']
+ )) {
+ unlink(
+ $info['dirname'] . "/" . $path . $config['relative_image_creation_name_to_prepend'][$k] . $info['filename'] . $config['relative_image_creation_name_to_append'][$k] . "." . $info['extension']
+ );
+ }
+ }
+ }
+
+ if (!$ftp && $config['fixed_image_creation']) {
+ foreach ($config['fixed_path_from_filemanager'] as $k => $path) {
+ if ($path != "" && $path[strlen($path) - 1] != "/") {
+ $path .= "/";
+ }
+
+ $base_dir = $path . substr_replace($info['dirname'] . "/", '', 0, strlen($config['current_path']));
+ if (file_exists(
+ $base_dir . $config['fixed_image_creation_name_to_prepend'][$k] . $info['filename'] . $config['fixed_image_creation_to_append'][$k] . "." . $info['extension']
+ )) {
+ unlink(
+ $base_dir . $config['fixed_image_creation_name_to_prepend'][$k] . $info['filename'] . $config['fixed_image_creation_to_append'][$k] . "." . $info['extension']
+ );
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Delete directory
+ *
+ * @param string $dir
+ *
+ * @return bool
+ */
+function deleteDir($dir, $ftp = null, $config = null)
+{
+ if ($ftp) {
+ try {
+ $ftp->rmdir($dir);
+ return true;
+ } catch (FtpClient\FtpException $e) {
+ return null;
+ }
+ } else {
+ if (!file_exists($dir) || isUploadDir($dir, $config)) {
+ return false;
+ }
+ if (!is_dir($dir)) {
+ return unlink($dir);
+ }
+ foreach (scandir($dir) as $item) {
+ if ($item == '.' || $item == '..') {
+ continue;
+ }
+ if (!deleteDir($dir . DIRECTORY_SEPARATOR . $item)) {
+ return false;
+ }
+ }
+ }
+
+ return rmdir($dir);
+}
+
+/**
+ * Make a file copy
+ *
+ * @param string $old_path
+ * @param string $name New file name without extension
+ *
+ * @return bool
+ */
+function duplicate_file($old_path, $name, $ftp = null, $config = null)
+{
+ $info = pathinfo($old_path);
+ $ext = "";
+ if (isset($info['extension']) && $info['extension']) {
+ $ext = "." . $info['extension'];
+ }
+ $new_path = $info['dirname'] . "/" . $name . $ext;
+ if ($ftp) {
+ try {
+ $tmp = time() . $name . $ext;
+ $ftp->get($tmp, "/" . $old_path, FTP_BINARY);
+ $ftp->put("/" . $new_path, $tmp, FTP_BINARY);
+ unlink($tmp);
+ return true;
+ } catch (FtpClient\FtpException $e) {
+ return null;
+ }
+ } else {
+ if (file_exists($old_path) && is_file($old_path)) {
+ if (file_exists($new_path) && $old_path == $new_path) {
+ return false;
+ }
+
+ return copy($old_path, $new_path);
+ }
+ }
}
/**
-* Rename file
-*
-* @param string $old_path File to rename
-* @param string $name New file name without extension
-* @param bool $transliteration
-*
-* @return bool
-*/
+ * Rename file
+ *
+ * @param string $old_path File to rename
+ * @param string $name New file name without extension
+ * @param null|\FtpClient\FtpClient $ftp
+ * @param null|array $config
+ * @return bool
+ */
function rename_file($old_path, $name, $ftp = null, $config = null)
{
- $name = fix_filename($name, $config);
- $info = pathinfo($old_path);
- $new_path = $info['dirname'] . "/" . $name . "." . $info['extension'];
- if($ftp){
- try{
- return $ftp->rename("/".$old_path, "/".$new_path);
- }catch(FtpClient\FtpException $e){
- return false;
- }
- }else{
- if (file_exists($old_path) && is_file($old_path))
- {
- $new_path = $info['dirname'] . "/" . $name . "." . $info['extension'];
- if (file_exists($new_path) && $old_path == $new_path)
- {
- return false;
- }
+ $name = fix_filename($name, $config);
+ $info = pathinfo($old_path);
+ $new_path = $info['dirname'] . "/" . $name . "." . $info['extension'];
+ if ($ftp) {
+ try {
+ return $ftp->rename("/" . $old_path, "/" . $new_path);
+ } catch (FtpClient\FtpException $e) {
+ return false;
+ }
+ } else {
+ if (file_exists($old_path) && is_file($old_path)) {
+ $new_path = $info['dirname'] . "/" . $name . "." . $info['extension'];
+ if (file_exists($new_path) && $old_path == $new_path) {
+ return false;
+ }
- return rename($old_path, $new_path);
- }
- }
+ return rename($old_path, $new_path);
+ }
+ }
}
-
-function url_exists($url){
- if (!$fp = curl_init($url)) return false;
+/**
+ * @param $url
+ * @return bool
+ */
+function url_exists($url)
+{
+ if (!$fp = curl_init($url)) {
+ return false;
+ }
return true;
}
+/**
+ * @return bool|string
+ */
+function tempdir()
+{
+ $tempfile = tempnam(sys_get_temp_dir(), '');
+
+ if (file_exists($tempfile)) {
+ unlink($tempfile);
+ }
-function tempdir() {
- $tempfile=tempnam(sys_get_temp_dir(),'');
- if (file_exists($tempfile)) { unlink($tempfile); }
mkdir($tempfile);
- if (is_dir($tempfile)) { return $tempfile; }
+
+ if (is_dir($tempfile)) {
+ return $tempfile;
+ }
}
/**
-* Rename directory
-*
-* @param string $old_path Directory to rename
-* @param string $name New directory name
-* @param bool $transliteration
-*
-* @return bool
-*/
+ * Rename directory
+ *
+ * @param string $old_path Directory to rename
+ * @param string $name New directory name
+ * @param null $ftp
+ * @param null|array $config
+ * @return bool
+ */
function rename_folder($old_path, $name, $ftp = null, $config = null)
{
- $name = fix_filename($name, $config, true);
- $new_path = fix_dirname($old_path) . "/" . $name;
- if($ftp){
- if($ftp->chdir("/".$old_path)){
- if(@$ftp->chdir($new_path)){
- return false;
- }
- return $ftp->rename("/".$old_path, "/".$new_path);
- }
- }else{
- if (file_exists($old_path) && is_dir($old_path) && !isUploadDir($old_path, $config))
- {
- if (file_exists($new_path) && $old_path == $new_path)
- {
- return false;
- }
- return rename($old_path, $new_path);
- }
- }
-}
-
-function ftp_con($config){
- if(isset($config['ftp_host']) && $config['ftp_host']){
- // *** Include the class
- include('include/FtpClient.php');
- include('include/FtpException.php');
- include('include/FtpWrapper.php');
-
- $ftp = new \FtpClient\FtpClient();
- try{
- $ftp->connect($config['ftp_host'],$config['ftp_ssl'],$config['ftp_port']);
- $ftp->login($config['ftp_user'], $config['ftp_pass']);
- $ftp->pasv(true);
- return $ftp;
- }catch(FtpClient\FtpException $e){
- echo "Error: ";
- echo $e->getMessage();
- echo " to server ";
- $tmp = $e->getTrace();
- echo $tmp[0]['args'][0];
- echo "
Please check configurations";
- die();
- }
- }else{
- return false;
- }
+ $name = fix_filename($name, $config, true);
+ $new_path = fix_dirname($old_path) . "/" . $name;
+ if ($ftp) {
+ if ($ftp->chdir("/" . $old_path)) {
+ if (@$ftp->chdir($new_path)) {
+ return false;
+ }
+ return $ftp->rename("/" . $old_path, "/" . $new_path);
+ }
+ } else {
+ if (file_exists($old_path) && is_dir($old_path) && !isUploadDir($old_path, $config)) {
+ if (file_exists($new_path) && $old_path == $new_path) {
+ return false;
+ }
+ return rename($old_path, $new_path);
+ }
+ }
}
/**
-* Create new image from existing file
-*
-* @param string $imgfile Source image file name
-* @param string $imgthumb Thumbnail file name
-* @param int $newwidth Thumbnail width
-* @param int $newheight Optional thumbnail height
-* @param string $option Type of resize
-*
-* @return bool
-* @throws \Exception
-*/
-function create_img($imgfile, $imgthumb, $newwidth, $newheight = null, $option = "crop",$config = array())
+ * @param array $config
+ * @return bool|\FtpClient\FtpClient
+ */
+function ftp_con($config)
{
- $result = false;
- if(isset($config['ftp_host']) && $config['ftp_host']){
- if(url_exists($imgfile)){
- $temp = tempnam('/tmp','RF');
- unlink($temp);
- $temp .=".".substr(strrchr($imgfile,'.'),1);
- $handle = fopen($temp, "w");
- fwrite($handle, file_get_contents($imgfile));
- fclose($handle);
- $imgfile= $temp;
- $save_ftp = $imgthumb;
- $imgthumb = $temp;
- }
- }
- if(file_exists($imgfile) || strpos($imgfile,'http')===0){
- if (strpos($imgfile,'http')===0 || image_check_memory_usage($imgfile, $newwidth, $newheight))
- {
- require_once('php_image_magician.php');
- try{
- $magicianObj = new imageLib($imgfile);
- $magicianObj->resizeImage($newwidth, $newheight, $option);
- $magicianObj->saveImage($imgthumb, 80);
- }catch (Exception $e){
- return $e->getMessage();
- }
- $result = true;
- }
- }
- if($result && isset($config['ftp_host']) && $config['ftp_host'] ){
- $ftp->put($save_ftp, $imgthumb, FTP_BINARY);
- unlink($imgthumb);
- }
+ if (isset($config['ftp_host']) && $config['ftp_host']) {
+ // *** Include the class
+ include __DIR__ . '/FtpClient.php';
+ include __DIR__ . '/FtpException.php';
+ include __DIR__ . '/FtpWrapper.php';
- return $result;
+ try {
+ $ftp = new \FtpClient\FtpClient();
+ $ftp->connect($config['ftp_host'], $config['ftp_ssl'], $config['ftp_port']);
+ $ftp->login($config['ftp_user'], $config['ftp_pass']);
+ $ftp->pasv(true);
+ return $ftp;
+ } catch (FtpClient\FtpException $e) {
+ echo "Error: ";
+ echo $e->getMessage();
+ echo " to server ";
+ $tmp = $e->getTrace();
+ echo $tmp[0]['args'][0];
+ echo "
Please check configurations";
+ die();
+ }
+ }
+
+ return false;
}
/**
-* Convert convert size in bytes to human readable
-*
-* @param int $size
-*
-* @return string
-*/
+ * Create new image from existing file
+ *
+ * @param string $imgfile Source image file name
+ * @param string $imgthumb Thumbnail file name
+ * @param int $newwidth Thumbnail width
+ * @param int $newheight Optional thumbnail height
+ * @param string $option Type of resize
+ *
+ * @param array $config
+ * @return bool
+ */
+function create_img($imgfile, $imgthumb, $newwidth, $newheight = null, $option = "crop", $config = array())
+{
+ $result = false;
+ if (isset($config['ftp_host']) && $config['ftp_host']) {
+ if (url_exists($imgfile)) {
+ $temp = tempnam('/tmp', 'RF');
+ unlink($temp);
+ $temp .= "." . substr(strrchr($imgfile, '.'), 1);
+ $handle = fopen($temp, "w");
+ fwrite($handle, file_get_contents($imgfile));
+ fclose($handle);
+ $imgfile = $temp;
+ $save_ftp = $imgthumb;
+ $imgthumb = $temp;
+ }
+ }
+
+ if (file_exists($imgfile) || strpos($imgfile, 'http') === 0) {
+ if (strpos($imgfile, 'http') === 0 || image_check_memory_usage($imgfile, $newwidth, $newheight)) {
+ require_once('php_image_magician.php');
+ try {
+ $magicianObj = new imageLib($imgfile);
+ $magicianObj->resizeImage($newwidth, $newheight, $option);
+ $magicianObj->saveImage($imgthumb, 80);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+ $result = true;
+ }
+ }
+
+ if ($result && isset($config['ftp_host']) && $config['ftp_host']) {
+ $ftp = ftp_con($config);
+ $ftp->put($save_ftp, $imgthumb, FTP_BINARY);
+ unlink($imgthumb);
+ }
+
+ return $result;
+}
+
+/**
+ * Convert convert size in bytes to human readable
+ *
+ * @param int $size
+ *
+ * @return string
+ */
function makeSize($size)
{
- $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
- $u = 0;
- while ((round($size / 1024) > 0) && ($u < 4))
- {
- $size = $size / 1024;
- $u++;
- }
+ $units = array('B', 'KB', 'MB', 'GB', 'TB');
+ $u = 0;
+ while ((round($size / 1024) > 0) && ($u < 4)) {
+ $size = $size / 1024;
+ $u++;
+ }
- return (number_format($size, 0) . " " . trans($units[ $u ]));
+ return (number_format($size, 0) . " " . trans($units[$u]));
}
/**
-* Determine directory size
-*
-* @param string $path
-*
-* @return int
-*/
-function folder_info($path,$count_hidden=true)
+ * Determine directory size
+ *
+ * @param string $path
+ * @param bool $count_hidden
+ * @return array
+ */
+function folder_info($path, $count_hidden = true)
{
- global $config;
- $total_size = 0;
- $files = scandir($path);
- $cleanPath = rtrim($path, '/') . '/';
- $files_count = 0;
- $folders_count = 0;
- foreach ($files as $t)
- {
- if ($t != "." && $t != "..")
- {
- if ($count_hidden or !(in_array($t,$config['hidden_folders']) or in_array($t,$config['hidden_files'])))
- {
- $currentFile = $cleanPath . $t;
- if (is_dir($currentFile))
- {
- list($size,$tmp,$tmp1) = folder_info($currentFile);
- $total_size += $size;
- $folders_count ++;
- }
- else
- {
- $size = filesize($currentFile);
- $total_size += $size;
- $files_count++;
- }
- }
- }
- }
+ global $config;
+ $total_size = 0;
+ $files = scandir($path);
+ $cleanPath = rtrim($path, '/') . '/';
+ $files_count = 0;
+ $folders_count = 0;
+ foreach ($files as $t) {
+ if ($t != "." && $t != "..") {
+ if ($count_hidden or !(in_array($t, $config['hidden_folders']) or in_array($t, $config['hidden_files']))) {
+ $currentFile = $cleanPath . $t;
+ if (is_dir($currentFile)) {
+ list($size, $tmp, $tmp1) = folder_info($currentFile);
+ $total_size += $size;
+ $folders_count++;
+ } else {
+ $size = filesize($currentFile);
+ $total_size += $size;
+ $files_count++;
+ }
+ }
+ }
+ }
- return array($total_size,$files_count,$folders_count);
+ return array($total_size, $files_count, $folders_count);
}
+
/**
-* Get number of files in a directory
-*
-* @param string $path
-*
-* @return int
-*/
-function filescount($path,$count_hidden=true)
+ * Get number of files in a directory
+ *
+ * @param string $path
+ *
+ * @return int
+ */
+function filescount($path, $count_hidden = true)
{
- global $config;
- $total_count = 0;
- $files = scandir($path);
- $cleanPath = rtrim($path, '/') . '/';
+ global $config;
+ $total_count = 0;
+ $files = scandir($path);
+ $cleanPath = rtrim($path, '/') . '/';
- foreach ($files as $t)
- {
- if ($t != "." && $t != "..")
- {
- if ($count_hidden or !(in_array($t,$config['hidden_folders']) or in_array($t,$config['hidden_files'])))
- {
- $currentFile = $cleanPath . $t;
- if (is_dir($currentFile))
- {
- $size = filescount($currentFile);
- $total_count += $size;
- }
- else
- {
- $total_count += 1;
- }
- }
- }
- }
+ foreach ($files as $t) {
+ if ($t != "." && $t != "..") {
+ if ($count_hidden or !(in_array($t, $config['hidden_folders']) or in_array($t, $config['hidden_files']))) {
+ $currentFile = $cleanPath . $t;
+ if (is_dir($currentFile)) {
+ $size = filescount($currentFile);
+ $total_count += $size;
+ } else {
+ $total_count += 1;
+ }
+ }
+ }
+ }
- return $total_count;
+ return $total_count;
}
+
/**
-* check if the current folder size plus the added size is over the overall size limite
-*
-* @param int $sizeAdded
-*
-* @return bool
-*/
+ * check if the current folder size plus the added size is over the overall size limite
+ *
+ * @param int $sizeAdded
+ *
+ * @return bool
+ */
function checkresultingsize($sizeAdded)
{
global $config;
- if ($config['MaxSizeTotal'] !== false && is_int($config['MaxSizeTotal'])) {
- list($sizeCurrentFolder,$fileCurrentNum,$foldersCurrentCount) = folder_info($config['current_path'],false);
- // overall size over limit
- if (($config['MaxSizeTotal'] * 1024 * 1024) < ($sizeCurrentFolder + $sizeAdded)) {
- return false;
- }
- }
- return true;
+ if ($config['MaxSizeTotal'] !== false && is_int($config['MaxSizeTotal'])) {
+ list($sizeCurrentFolder, $fileCurrentNum, $foldersCurrentCount) = folder_info($config['current_path'], false);
+ // overall size over limit
+ if (($config['MaxSizeTotal'] * 1024 * 1024) < ($sizeCurrentFolder + $sizeAdded)) {
+ return false;
+ }
+ }
+ return true;
}
/**
-* Create directory for images and/or thumbnails
-*
-* @param string $path
-* @param string $path_thumbs
-*/
-function create_folder($path = null, $path_thumbs = null,$ftp = null,$config = null)
+ * Create directory for images and/or thumbnails
+ *
+ * @param string $path
+ * @param string $path_thumbs
+ *
+ * @return bool
+ */
+function create_folder($path = null, $path_thumbs = null, $ftp = null, $config = null)
{
- if($ftp){
- $ftp->mkdir($path);
- $ftp->mkdir($path_thumbs);
- }else{
- if(file_exists($path) || file_exists($path_thumbs)){
- return false;
- }
- $oldumask = umask(0);
- $permission = 0755;
- if(isset($config['folderPermission'])){
- $permission = $config['folderPermission'];
- }
- if ($path && !file_exists($path))
- {
- mkdir($path, $permission, true);
- } // or even 01777 so you get the sticky bit set
- if ($path_thumbs)
- {
- mkdir($path_thumbs, $permission, true) or die("$path_thumbs cannot be found");
- } // or even 01777 so you get the sticky bit set
- umask($oldumask);
- return true;
- }
+ if ($ftp) {
+ $result_path = $result_thumb = false;
+ $result_path = $ftp->mkdir($path);
+ $result_thumb = $ftp->mkdir($path_thumbs);
+ if (!$result_thumb || !$result_path) {
+ return false;
+ }
+ return true;
+ } else {
+ if (file_exists($path) || file_exists($path_thumbs)) {
+ return false;
+ }
+ $oldumask = umask(0);
+ $permission = 0755;
+ if (isset($config['folderPermission'])) {
+ $permission = $config['folderPermission'];
+ }
+ if ($path && !file_exists($path)) {
+ mkdir($path, $permission, true);
+ } // or even 01777 so you get the sticky bit set
+ if ($path_thumbs) {
+ mkdir($path_thumbs, $permission, true) or die("$path_thumbs cannot be found");
+ } // or even 01777 so you get the sticky bit set
+ umask($oldumask);
+ return true;
+ }
}
/**
-* Get file extension present in directory
-*
-* @param string $path
-* @param string $ext
-*/
+ * Get file extension present in directory
+ *
+ * @param string $path
+ * @param string $ext
+ */
function check_files_extensions_on_path($path, $ext)
{
- if ( ! is_dir($path))
- {
- $fileinfo = pathinfo($path);
- if ( ! in_array(mb_strtolower($fileinfo['extension']), $ext))
- {
- unlink($path);
- }
- }
- else
- {
- $files = scandir($path);
- foreach ($files as $file)
- {
- check_files_extensions_on_path(trim($path, '/') . "/" . $file, $ext);
- }
- }
+ if (!is_dir($path)) {
+ $fileinfo = pathinfo($path);
+ if (!in_array(mb_strtolower($fileinfo['extension']), $ext)) {
+ unlink($path);
+ }
+ } else {
+ $files = scandir($path);
+ foreach ($files as $file) {
+ check_files_extensions_on_path(trim($path, '/') . "/" . $file, $ext);
+ }
+ }
}
/**
-* Check file extension
-*
-* @param string $extension
-* @param array $config
-*/
-
-function check_file_extension($extension,$config){
- $check = false;
- if (!$config['ext_blacklist']) {
- if(in_array(mb_strtolower($extension), $conf['ext'])){
- $check = true;
- }
+ * Check file extension
+ *
+ * @param string $extension
+ * @param array $config
+ * @return bool
+ */
+function check_file_extension($extension, $config)
+{
+ $check = false;
+ if (!$config['ext_blacklist']) {
+ if (in_array(mb_strtolower($extension), $config['ext'])) {
+ $check = true;
+ }
} else {
- if(!in_array(mb_strtolower($extension), $conf['ext_blacklist'])){
- $check = true;
- }
+ if (!in_array(mb_strtolower($extension), $config['ext_blacklist'])) {
+ $check = true;
+ }
}
- if($config['files_without_extension'] && $extension == ''){
- $check = true;
- }
+ if ($config['files_without_extension'] && $extension == '') {
+ $check = true;
+ }
- return $check;
+ return $check;
}
/**
-* Get file extension present in PHAR file
-*
-* @param string $phar
-* @param array $files
-* @param string $basepath
-* @param string $ext
-*/
+ * Get file extension present in PHAR file
+ *
+ * @param string $phar
+ * @param array $files
+ * @param string $basepath
+ * @param array $config
+ */
function check_files_extensions_on_phar($phar, &$files, $basepath, $config)
{
- foreach ($phar as $file)
- {
- if ($file->isFile())
- {
- if (check_file_extension($file->getExtension()))
- {
- $files[] = $basepath . $file->getFileName();
- }
- }
- else
- {
- if ($file->isDir())
- {
- $iterator = new DirectoryIterator($file);
- check_files_extensions_on_phar($iterator, $files, $basepath . $file->getFileName() . '/', $config);
- }
- }
- }
+ foreach ($phar as $file) {
+ if ($file->isFile()) {
+ if (check_file_extension($file->getExtension())) {
+ $files[] = $basepath . $file->getFileName();
+ }
+ } else {
+ if ($file->isDir()) {
+ $iterator = new DirectoryIterator($file);
+ check_files_extensions_on_phar($iterator, $files, $basepath . $file->getFileName() . '/', $config);
+ }
+ }
+ }
}
/**
-* Cleanup input
-*
-* @param string $str
-*
-* @return string
-*/
+ * Cleanup input
+ *
+ * @param string $str
+ *
+ * @return string
+ */
function fix_get_params($str)
{
- return strip_tags(preg_replace("/[^a-zA-Z0-9\.\[\]_| -]/", '', $str));
+ //return strip_tags(preg_replace("/[^a-zA-Z0-9\.\[\]_| -]/", '', $str));
+ return htmlentities(strip_tags(stripslashes($str)), ENT_COMPAT, "UTF-8");
}
-
/**
-* Check extension
-*
-* @param string $extension
-* @param array $config
-*
-* @return bool
-*/
-function check_extension($extension,$config){
- $extension = fix_strtolower($extension);
- if((!$config['ext_blacklist'] && !in_array($extension, $config['ext'])) || ($config['ext_blacklist'] && in_array($extension, $config['ext_blacklist']))){
- return false;
- }
- return true;
+ * Check extension
+ *
+ * @param string $extension
+ * @param array $config
+ *
+ * @return bool
+ */
+function check_extension($extension, $config)
+{
+ $extension = fix_strtolower($extension);
+ if ((!$config['ext_blacklist'] && !in_array($extension, $config['ext'])) || ($config['ext_blacklist'] && in_array(
+ $extension,
+ $config['ext_blacklist']
+ ))) {
+ return false;
+ }
+ return true;
}
-
-
-
/**
-* Sanitize filename
-*
-* @param string $str
-*
-* @return string
-*/
+ * Sanitize filename
+ *
+ * @param string $str
+ *
+ * @return string
+ */
function sanitize($str)
{
- return strip_tags(htmlspecialchars($str));
+ return strip_tags(htmlspecialchars($str));
}
/**
-* Cleanup filename
-*
-* @param string $str
-* @param bool $transliteration
-* @param bool $convert_spaces
-* @param string $replace_with
-* @param bool $is_folder
-*
-* @return string
-*/
+ * Cleanup filename
+ *
+ * @param string $str
+ * @param array $config
+ * @param bool $is_folder
+ *
+ * @return string
+ */
function fix_filename($str, $config, $is_folder = false)
{
- $str = sanitize($str);
- if ($config['convert_spaces'])
- {
- $str = str_replace(' ', $config['replace_with'], $str);
- }
+ $str = sanitize($str);
+ if ($config['convert_spaces']) {
+ $str = str_replace(' ', $config['replace_with'], $str);
+ }
- if ($config['transliteration'])
- {
- if (!mb_detect_encoding($str, 'UTF-8', true))
- {
- $str = utf8_encode($str);
- }
- if (function_exists('transliterator_transliterate'))
- {
- $str = transliterator_transliterate('Any-Latin; Latin-ASCII', $str);
- }
- else
- {
- $str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
- }
+ if ($config['transliteration']) {
+ if (!mb_detect_encoding($str, 'UTF-8', true)) {
+ $str = utf8_encode($str);
+ }
+ if (function_exists('transliterator_transliterate')) {
+ $str = transliterator_transliterate('Any-Latin; Latin-ASCII', $str);
+ } else {
+ $str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
+ }
- $str = preg_replace("/[^a-zA-Z0-9\.\[\]_| -]/", '', $str);
- }
+ $str = preg_replace("/[^a-zA-Z0-9\.\[\]_| -]/", '', $str);
+ }
- $str = str_replace(array( '"', "'", "/", "\\" ), "", $str);
- $str = strip_tags($str);
+ $str = str_replace(array('"', "'", "/", "\\"), "", $str);
+ $str = strip_tags($str);
- // Empty or incorrectly transliterated filename.
- // Here is a point: a good file UNKNOWN_LANGUAGE.jpg could become .jpg in previous code.
- // So we add that default 'file' name to fix that issue.
- if (!$config['empty_filename'] && strpos($str, '.') === 0 && $is_folder === false)
- {
- $str = 'file' . $str;
- }
+ // Empty or incorrectly transliterated filename.
+ // Here is a point: a good file UNKNOWN_LANGUAGE.jpg could become .jpg in previous code.
+ // So we add that default 'file' name to fix that issue.
+ if (!$config['empty_filename'] && strpos($str, '.') === 0 && $is_folder === false) {
+ $str = 'file' . $str;
+ }
- return trim($str);
+ return trim($str);
}
/**
-* Cleanup directory name
-*
-* @param string $str
-*
-* @return string
-*/
+ * Cleanup directory name
+ *
+ * @param string $str
+ *
+ * @return string
+ */
function fix_dirname($str)
{
- return str_replace('~', ' ', dirname(str_replace(' ', '~', $str)));
+ return str_replace('~', ' ', dirname(str_replace(' ', '~', $str)));
}
/**
-* Correct strtoupper handling
-*
-* @param string $str
-*
-* @return string
-*/
+ * Correct strtoupper handling
+ *
+ * @param string $str
+ *
+ * @return string
+ */
function fix_strtoupper($str)
{
- if (function_exists('mb_strtoupper'))
- {
- return mb_strtoupper($str);
- }
- else
- {
- return strtoupper($str);
- }
+ if (function_exists('mb_strtoupper')) {
+ return mb_strtoupper($str);
+ } else {
+ return strtoupper($str);
+ }
}
/**
-* Correct strtolower handling
-*
-* @param string $str
-*
-* @return string
-*/
+ * Correct strtolower handling
+ *
+ * @param string $str
+ *
+ * @return string
+ */
function fix_strtolower($str)
{
- if (function_exists('mb_strtoupper'))
- {
- return mb_strtolower($str);
- }
- else
- {
- return strtolower($str);
- }
+ if (function_exists('mb_strtolower')) {
+ return mb_strtolower($str);
+ } else {
+ return strtolower($str);
+ }
}
+/**
+ * @param string $path
+ * @param array $config
+ * @return string
+ */
function fix_path($path, $config)
{
- $info = pathinfo($path);
- $tmp_path = $info['dirname'];
- $str = fix_filename($info['filename'], $config);
- if ($tmp_path != "")
- {
- return $tmp_path . DIRECTORY_SEPARATOR . $str;
- }
- else
- {
- return $str;
- }
+ $info = pathinfo($path);
+ $tmp_path = $info['dirname'];
+ $str = fix_filename($info['filename'], $config);
+ if ($tmp_path != "") {
+ return $tmp_path . DIRECTORY_SEPARATOR . $str;
+ }
+ return $str;
}
/**
-* @param $current_path
-* @param $fld
-*
-* @return bool
-*/
+ * @param string $current_path
+ * @param $fld
+ *
+ * @return bool
+ */
function config_loading($current_path, $fld)
{
- if (file_exists($current_path . $fld . ".config"))
- {
- require_once($current_path . $fld . ".config");
+ if (file_exists($current_path . $fld . ".config")) {
+ require_once($current_path . $fld . ".config");
- return true;
- }
- echo "!!!!" . $parent = fix_dirname($fld);
- if ($parent != "." && ! empty($parent))
- {
- config_loading($current_path, $parent);
- }
+ return true;
+ }
+ echo "!!!!" . $parent = fix_dirname($fld);
+ if ($parent != "." && !empty($parent)) {
+ config_loading($current_path, $parent);
+ }
- return false;
+ return false;
}
/**
-* Check if memory is enough to process image
-*
-* @param string $img
-* @param int $max_breedte
-* @param int $max_hoogte
-*
-* @return bool
-*/
+ * Check if memory is enough to process image
+ *
+ * @param string $img
+ * @param int $max_breedte
+ * @param int $max_hoogte
+ *
+ * @return bool
+ */
function image_check_memory_usage($img, $max_breedte, $max_hoogte)
{
- if (file_exists($img))
- {
- $K64 = 65536; // number of bytes in 64K
- $memory_usage = memory_get_usage();
- if(ini_get('memory_limit') > 0 ){
-
- $mem = ini_get('memory_limit');
- $memory_limit = 0;
- if (strpos($mem, 'M') !== false) $memory_limit = abs(intval(str_replace(array('M'), '', $mem) * 1024 * 1024));
- if (strpos($mem, 'G') !== false) $memory_limit = abs(intval(str_replace(array('G'), '', $mem) * 1024 * 1024 * 1024));
-
- $image_properties = getimagesize($img);
- $image_width = $image_properties[0];
- $image_height = $image_properties[1];
- if (isset($image_properties['bits']))
- $image_bits = $image_properties['bits'];
- else
- $image_bits = 0;
- $image_memory_usage = $K64 + ($image_width * $image_height * ($image_bits >> 3) * 2);
- $thumb_memory_usage = $K64 + ($max_breedte * $max_hoogte * ($image_bits >> 3) * 2);
- $memory_needed = abs(intval($memory_usage + $image_memory_usage + $thumb_memory_usage));
+ if (file_exists($img)) {
+ $K64 = 65536; // number of bytes in 64K
+ $memory_usage = memory_get_usage();
+ if (ini_get('memory_limit') > 0) {
+ $mem = ini_get('memory_limit');
+ $memory_limit = 0;
+ if (strpos($mem, 'M') !== false) {
+ $memory_limit = abs(intval(str_replace(array('M'), '', $mem) * 1024 * 1024));
+ }
+ if (strpos($mem, 'G') !== false) {
+ $memory_limit = abs(intval(str_replace(array('G'), '', $mem) * 1024 * 1024 * 1024));
+ }
- if ($memory_needed > $memory_limit)
- {
- return false;
- }
- }
- return true;
- }
- return false;
+ if (($image_properties = getimagesize($img)) === false) {
+ return false;
+ }
+ $image_width = $image_properties[0];
+ $image_height = $image_properties[1];
+
+ if ($image_properties[2] == IMAGETYPE_PNG) {
+ // PHP's getimagesize() doesn't return the number of channels for PNG files
+ require_once __DIR__ . '/get_png_imageinfo.php';
+ if ($png_properties = get_png_imageinfo($img)) {
+ $image_properties['bits'] = $png_properties['bits'];
+ $image_properties['channels'] = $png_properties['channels'];
+ }
+ }
+
+ $image_bits = 0;
+ $image_channels = 0;
+ if (isset($image_properties['bits'])) {
+ $image_bits = $image_properties['bits'];
+ $image_channels = isset($image_properties['channels']) ? $image_properties['channels'] : 1;
+ }
+
+ if ($image_properties[2] == IMAGETYPE_GIF) {
+ // GIF supports up to 8 bits per pixel
+ if (empty($image_bits)) {
+ $image_bits = 8;
+ }
+ // GIF uses indexed color which obviates channels
+ $image_channels = 1;
+ }
+
+ $image_memory_usage = $K64 + ($image_width * $image_height * ($image_bits * $image_channels / 8) * 2);
+ $thumb_memory_usage = $K64 + ($max_breedte * $max_hoogte * ($image_bits * $image_channels / 8) * 2);
+ $memory_needed = abs(intval($memory_usage + $image_memory_usage + $thumb_memory_usage));
+
+ if ($memory_needed > $memory_limit) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
}
/**
-* Check is string is ended with needle
-*
-* @param string $haystack
-* @param string $needle
-*
-* @return bool
-*/
-if(!function_exists('ends_with')){
- function ends_with($haystack, $needle)
- {
- return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
- }
+ * Check is string is ended with needle
+ *
+ * @param string $haystack
+ * @param string $needle
+ *
+ * @return bool
+ */
+if (!function_exists('ends_with')) {
+ function ends_with($haystack, $needle)
+ {
+ return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
+ }
}
/**
-* TODO REFACTOR THIS!
-*
-* @param $targetPath
-* @param $targetFile
-* @param $name
-* @param $current_path
-* @param $config
-* relative_image_creation
-* relative_path_from_current_pos
-* relative_image_creation_name_to_prepend
-* relative_image_creation_name_to_append
-* relative_image_creation_width
-* relative_image_creation_height
-* relative_image_creation_option
-* fixed_image_creation
-* fixed_path_from_filemanager
-* fixed_image_creation_name_to_prepend
-* fixed_image_creation_to_append
-* fixed_image_creation_width
-* fixed_image_creation_height
-* fixed_image_creation_option
-*
-* @return bool
-*/
+ * TODO REFACTOR THIS!
+ *
+ * @param $targetPath
+ * @param $targetFile
+ * @param $name
+ * @param $current_path
+ * @param $config
+ * relative_image_creation
+ * relative_path_from_current_pos
+ * relative_image_creation_name_to_prepend
+ * relative_image_creation_name_to_append
+ * relative_image_creation_width
+ * relative_image_creation_height
+ * relative_image_creation_option
+ * fixed_image_creation
+ * fixed_path_from_filemanager
+ * fixed_image_creation_name_to_prepend
+ * fixed_image_creation_to_append
+ * fixed_image_creation_width
+ * fixed_image_creation_height
+ * fixed_image_creation_option
+ *
+ * @return bool
+ */
function new_thumbnails_creation($targetPath, $targetFile, $name, $current_path, $config)
{
- //create relative thumbs
- $all_ok = true;
+ //create relative thumbs
+ $all_ok = true;
- $info = pathinfo($name);
- $info['filename'] = fix_filename($info['filename'],$config);
- if ($config['relative_image_creation'])
- {
- foreach ($config['relative_path_from_current_pos'] as $k => $path)
- {
- if ($path != "" && $path[ strlen($path) - 1 ] != "/")
- {
- $path .= "/";
- }
- if ( ! file_exists($targetPath . $path))
- {
- create_folder($targetPath . $path, false);
- }
- if ( ! ends_with($targetPath, $path))
- {
- if ( ! create_img($targetFile, $targetPath . $path . $config['relative_image_creation_name_to_prepend'][ $k ] . $info['filename'] . $config['relative_image_creation_name_to_append'][ $k ] . "." . $info['extension'], $config['relative_image_creation_width'][ $k ], $config['relative_image_creation_height'][ $k ], $config['relative_image_creation_option'][ $k ]))
- {
- $all_ok = false;
- }
- }
- }
- }
+ $info = pathinfo($name);
+ $info['filename'] = fix_filename($info['filename'], $config);
+ if ($config['relative_image_creation']) {
+ foreach ($config['relative_path_from_current_pos'] as $k => $path) {
+ if ($path != "" && $path[strlen($path) - 1] != "/") {
+ $path .= "/";
+ }
+ if (!file_exists($targetPath . $path)) {
+ create_folder($targetPath . $path, false);
+ }
+ if (!ends_with($targetPath, $path)) {
+ if (!create_img(
+ $targetFile,
+ $targetPath . $path . $config['relative_image_creation_name_to_prepend'][$k] . $info['filename'] . $config['relative_image_creation_name_to_append'][$k] . "." . $info['extension'],
+ $config['relative_image_creation_width'][$k],
+ $config['relative_image_creation_height'][$k],
+ $config['relative_image_creation_option'][$k]
+ )) {
+ $all_ok = false;
+ }
+ }
+ }
+ }
- //create fixed thumbs
- if ($config['fixed_image_creation'])
- {
- foreach ($config['fixed_path_from_filemanager'] as $k => $path)
- {
- if ($path != "" && $path[ strlen($path) - 1 ] != "/")
- {
- $path .= "/";
- }
- $base_dir = $path . substr_replace($targetPath, '', 0, strlen($current_path));
- if ( ! file_exists($base_dir))
- {
- create_folder($base_dir, false);
- }
- if ( ! create_img($targetFile, $base_dir . $config['fixed_image_creation_name_to_prepend'][ $k ] . $info['filename'] . $config['fixed_image_creation_to_append'][ $k ] . "." . $info['extension'], $config['fixed_image_creation_width'][ $k ], $config['fixed_image_creation_height'][ $k ], $config['fixed_image_creation_option'][ $k ]))
- {
- $all_ok = false;
- }
- }
- }
+ //create fixed thumbs
+ if ($config['fixed_image_creation']) {
+ foreach ($config['fixed_path_from_filemanager'] as $k => $path) {
+ if ($path != "" && $path[strlen($path) - 1] != "/") {
+ $path .= "/";
+ }
+ $base_dir = $path . substr_replace($targetPath, '', 0, strlen($current_path));
+ if (!file_exists($base_dir)) {
+ create_folder($base_dir, false);
+ }
+ if (!create_img(
+ $targetFile,
+ $base_dir . $config['fixed_image_creation_name_to_prepend'][$k] . $info['filename'] . $config['fixed_image_creation_to_append'][$k] . "." . $info['extension'],
+ $config['fixed_image_creation_width'][$k],
+ $config['fixed_image_creation_height'][$k],
+ $config['fixed_image_creation_option'][$k]
+ )) {
+ $all_ok = false;
+ }
+ }
+ }
- return $all_ok;
+ return $all_ok;
}
/**
-* Get a remote file, using whichever mechanism is enabled
-*
-* @param string $url
-*
-* @return bool|mixed|string
-*/
+ * Get a remote file, using whichever mechanism is enabled
+ *
+ * @param string $url
+ *
+ * @return bool|mixed|string
+ */
function get_file_by_url($url)
{
- if (ini_get('allow_url_fopen'))
- {
- $arrContextOptions=array(
- "ssl"=>array(
- "verify_peer"=>false,
- "verify_peer_name"=>false,
- ),
- );
- return file_get_contents($url, false, stream_context_create($arrContextOptions));
- }
- if ( ! function_exists('curl_version'))
- {
- return false;
- }
+ if (ini_get('allow_url_fopen')) {
+ $arrContextOptions = array(
+ "ssl" => array(
+ "verify_peer" => false,
+ "verify_peer_name" => false,
+ ),
+ );
+ return file_get_contents($url, false, stream_context_create($arrContextOptions));
+ }
+ if (!function_exists('curl_version')) {
+ return false;
+ }
- $ch = curl_init();
+ $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_URL, $url);
- $data = curl_exec($ch);
- curl_close($ch);
+ $data = curl_exec($ch);
+ curl_close($ch);
- return $data;
+ return $data;
}
/**
-* test for dir/file writability properly
-*
-* @param string $dir
-*
-* @return bool
-*/
+ * test for dir/file writability properly
+ *
+ * @param string $dir
+ *
+ * @return bool
+ */
function is_really_writable($dir)
{
- $dir = rtrim($dir, '/');
- // linux, safe off
- if (DIRECTORY_SEPARATOR == '/' && @ini_get("safe_mode") == false)
- {
- return is_writable($dir);
- }
+ $dir = rtrim($dir, '/');
+ // linux, safe off
+ if (DIRECTORY_SEPARATOR == '/' && @ini_get("safe_mode") == false) {
+ return is_writable($dir);
+ }
- // Windows, safe ON. (have to write a file :S)
- if (is_dir($dir))
- {
- $dir = $dir . '/' . md5(mt_rand(1, 1000) . mt_rand(1, 1000));
+ // Windows, safe ON. (have to write a file :S)
+ if (is_dir($dir)) {
+ $dir = $dir . '/' . md5(mt_rand(1, 1000) . mt_rand(1, 1000));
- if (($fp = @fopen($dir, 'ab')) === false)
- {
- return false;
- }
+ if (($fp = @fopen($dir, 'ab')) === false) {
+ return false;
+ }
- fclose($fp);
- @chmod($dir, 0755);
- @unlink($dir);
+ fclose($fp);
+ @chmod($dir, 0755);
+ @unlink($dir);
- return true;
- }
- elseif ( ! is_file($dir) || ($fp = @fopen($dir, 'ab')) === false)
- {
- return false;
- }
+ return true;
+ } elseif (!is_file($dir) || ($fp = @fopen($dir, 'ab')) === false) {
+ return false;
+ }
- fclose($fp);
+ fclose($fp);
- return true;
+ return true;
}
/**
-* Check if a function is callable.
-* Some servers disable copy,rename etc.
-*
-* @parm string $name
-*
-* @return bool
-*/
+ * Check if a function is callable.
+ * Some servers disable copy,rename etc.
+ *
+ * @parm string $name
+ *
+ * @return bool
+ */
function is_function_callable($name)
{
- if (function_exists($name) === false)
- {
- return false;
- }
- $disabled = explode(',', ini_get('disable_functions'));
+ if (function_exists($name) === false) {
+ return false;
+ }
+ $disabled = explode(',', ini_get('disable_functions'));
- return ! in_array($name, $disabled);
+ return !in_array($name, $disabled);
}
/**
-* recursivly copies everything
-*
-* @param string $source
-* @param string $destination
-* @param bool $is_rec
-*/
+ * Recursively copies everything
+ *
+ * @param string $source
+ * @param string $destination
+ * @param bool $is_rec
+ */
function rcopy($source, $destination, $is_rec = false)
{
- if (is_dir($source))
- {
- if ($is_rec === false)
- {
- $pinfo = pathinfo($source);
- $destination = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
- }
- if (is_dir($destination) === false)
- {
- mkdir($destination, 0755, true);
- }
+ if (is_dir($source)) {
+ if ($is_rec === false) {
+ $pinfo = pathinfo($source);
+ $destination = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
+ }
+ if (is_dir($destination) === false) {
+ mkdir($destination, 0755, true);
+ }
- $files = scandir($source);
- foreach ($files as $file)
- {
- if ($file != "." && $file != "..")
- {
- rcopy($source . DIRECTORY_SEPARATOR . $file, rtrim($destination, '/') . DIRECTORY_SEPARATOR . $file, true);
- }
- }
- }
- else
- {
- if (file_exists($source))
- {
- if (is_dir($destination) === true)
- {
- $pinfo = pathinfo($source);
- $dest2 = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
- }
- else
- {
- $dest2 = $destination;
- }
+ $files = scandir($source);
+ foreach ($files as $file) {
+ if ($file != "." && $file != "..") {
+ rcopy(
+ $source . DIRECTORY_SEPARATOR . $file,
+ rtrim($destination, '/') . DIRECTORY_SEPARATOR . $file,
+ true
+ );
+ }
+ }
+ } else {
+ if (file_exists($source)) {
+ if (is_dir($destination) === true) {
+ $pinfo = pathinfo($source);
+ $dest2 = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
+ } else {
+ $dest2 = $destination;
+ }
- copy($source, $dest2);
- }
- }
+ copy($source, $dest2);
+ }
+ }
}
-
-
/**
-* recursivly renames everything
-*
-* I know copy and rename could be done with just one function
-* but i split the 2 because sometimes rename fails on windows
-* Need more feedback from users and refactor if needed
-*
-* @param string $source
-* @param string $destination
-* @param bool $is_rec
-*/
+ * Recursively renames everything
+ *
+ * I know copy and rename could be done with just one function
+ * but i split the 2 because sometimes rename fails on windows
+ * Need more feedback from users and refactor if needed
+ *
+ * @param string $source
+ * @param string $destination
+ * @param bool $is_rec
+ */
function rrename($source, $destination, $is_rec = false)
{
- if (is_dir($source))
- {
- if ($is_rec === false)
- {
- $pinfo = pathinfo($source);
- $destination = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
- }
- if (is_dir($destination) === false)
- {
- mkdir($destination, 0755, true);
- }
+ if (is_dir($source)) {
+ if ($is_rec === false) {
+ $pinfo = pathinfo($source);
+ $destination = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
+ }
+ if (is_dir($destination) === false) {
+ mkdir($destination, 0755, true);
+ }
- $files = scandir($source);
- foreach ($files as $file)
- {
- if ($file != "." && $file != "..")
- {
- rrename($source . DIRECTORY_SEPARATOR . $file, rtrim($destination, '/') . DIRECTORY_SEPARATOR . $file, true);
- }
- }
- }
- else
- {
- if (file_exists($source))
- {
- if (is_dir($destination) === true)
- {
- $pinfo = pathinfo($source);
- $dest2 = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
- }
- else
- {
- $dest2 = $destination;
- }
+ $files = scandir($source);
+ foreach ($files as $file) {
+ if ($file != "." && $file != "..") {
+ rrename(
+ $source . DIRECTORY_SEPARATOR . $file,
+ rtrim($destination, '/') . DIRECTORY_SEPARATOR . $file,
+ true
+ );
+ }
+ }
+ } else {
+ if (file_exists($source)) {
+ if (is_dir($destination) === true) {
+ $pinfo = pathinfo($source);
+ $dest2 = rtrim($destination, '/') . DIRECTORY_SEPARATOR . $pinfo['basename'];
+ } else {
+ $dest2 = $destination;
+ }
- rename($source, $dest2);
- }
- }
+ rename($source, $dest2);
+ }
+ }
}
-// On windows rename leaves folders sometime
-// This will clear leftover folders
-// After more feedback will merge it with rrename
+
+/**
+ * On windows rename leaves folders sometime
+ * This will clear leftover folders
+ * After more feedback will merge it with rrename
+ *
+ * @param $source
+ * @return bool
+ */
function rrename_after_cleaner($source)
{
- $files = scandir($source);
+ $files = scandir($source);
- foreach ($files as $file)
- {
- if ($file != "." && $file != "..")
- {
- if (is_dir($source . DIRECTORY_SEPARATOR . $file))
- {
- rrename_after_cleaner($source . DIRECTORY_SEPARATOR . $file);
- }
- else
- {
- unlink($source . DIRECTORY_SEPARATOR . $file);
- }
- }
- }
+ foreach ($files as $file) {
+ if ($file != "." && $file != "..") {
+ if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
+ rrename_after_cleaner($source . DIRECTORY_SEPARATOR . $file);
+ } else {
+ unlink($source . DIRECTORY_SEPARATOR . $file);
+ }
+ }
+ }
- return rmdir($source);
+ return rmdir($source);
}
/**
-* Recursive chmod
-* @param string $source
-* @param int $mode
-* @param string $rec_option
-* @param bool $is_rec
-*/
+ * Recursive chmod
+ * @param string $source
+ * @param int $mode
+ * @param string $rec_option
+ * @param bool $is_rec
+ */
function rchmod($source, $mode, $rec_option = "none", $is_rec = false)
{
- if ($rec_option == "none")
- {
- chmod($source, $mode);
- }
- else
- {
- if ($is_rec === false)
- {
- chmod($source, $mode);
- }
+ if ($rec_option == "none") {
+ chmod($source, $mode);
+ } else {
+ if ($is_rec === false) {
+ chmod($source, $mode);
+ }
- $files = scandir($source);
+ $files = scandir($source);
- foreach ($files as $file)
- {
- if ($file != "." && $file != "..")
- {
- if (is_dir($source . DIRECTORY_SEPARATOR . $file))
- {
- if ($rec_option == "folders" || $rec_option == "both")
- {
- chmod($source . DIRECTORY_SEPARATOR . $file, $mode);
- }
- rchmod($source . DIRECTORY_SEPARATOR . $file, $mode, $rec_option, true);
- }
- else
- {
- if ($rec_option == "files" || $rec_option == "both")
- {
- chmod($source . DIRECTORY_SEPARATOR . $file, $mode);
- }
- }
- }
- }
- }
+ foreach ($files as $file) {
+ if ($file != "." && $file != "..") {
+ if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
+ if ($rec_option == "folders" || $rec_option == "both") {
+ chmod($source . DIRECTORY_SEPARATOR . $file, $mode);
+ }
+ rchmod($source . DIRECTORY_SEPARATOR . $file, $mode, $rec_option, true);
+ } else {
+ if ($rec_option == "files" || $rec_option == "both") {
+ chmod($source . DIRECTORY_SEPARATOR . $file, $mode);
+ }
+ }
+ }
+ }
+ }
}
/**
-* @param string $input
-* @param bool $trace
-* @param bool $halt
-*/
+ * @param string $input
+ * @param bool $trace
+ * @param bool $halt
+ */
function debugger($input, $trace = false, $halt = false)
{
- ob_start();
+ ob_start();
- echo "
----- DEBUG DUMP -----";
- echo "
";
- var_dump($input);
- echo "
";
+ echo "
----- DEBUG DUMP -----";
+ echo "
";
+ var_dump($input);
+ echo "
";
- if ($trace)
- {
- if (is_php('5.3.6'))
- {
- $debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
- }
- else
- {
- $debug = debug_backtrace(false);
- }
+ if ($trace) {
+ if (is_php('5.3.6')) {
+ $debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ } else {
+ $debug = debug_backtrace(false);
+ }
- echo "
-----STACK TRACE-----";
- echo "
";
- var_dump($debug);
- echo "
";
- }
+ echo "
-----STACK TRACE-----";
+ echo "
";
+ var_dump($debug);
+ echo "
";
+ }
- echo "";
- echo "---------------------------
";
+ echo "";
+ echo "---------------------------
";
- $ret = ob_get_contents();
- ob_end_clean();
+ $ret = ob_get_contents();
+ ob_end_clean();
- echo $ret;
+ echo $ret;
- if ($halt == true)
- {
- exit();
- }
+ if ($halt == true) {
+ exit();
+ }
}
/**
-* @param string $version
-*
-* @return bool
-*/
+ * @param string $version
+ *
+ * @return bool
+ */
function is_php($version = '5.0.0')
{
- static $phpVer;
- $version = (string) $version;
+ static $phpVer;
+ $version = (string)$version;
- if ( ! isset($phpVer[ $version ]))
- {
- $phpVer[ $version ] = (version_compare(PHP_VERSION, $version) < 0) ? false : true;
- }
+ if (!isset($phpVer[$version])) {
+ $phpVer[$version] = (version_compare(PHP_VERSION, $version) < 0) ? false : true;
+ }
- return $phpVer[ $version ];
+ return $phpVer[$version];
}
/**
-* Return the caller location if set in config.php
-* @param string $version
-*
-* @return bool
-*/
+ * Return the caller location if set in config.php
+ *
+ * @return bool
+ */
function AddErrorLocation()
{
- if (defined('DEBUG_ERROR_MESSAGE') and DEBUG_ERROR_MESSAGE) {
- $pile=debug_backtrace();
- return " (@".$pile[0]["file"]."#".$pile[0]["line"].")";
- }
- return "";
+ if (defined('DEBUG_ERROR_MESSAGE') && DEBUG_ERROR_MESSAGE) {
+ $pile = debug_backtrace();
+ return " (@" . $pile[0]["file"] . "#" . $pile[0]["line"] . ")";
+ }
+ return "";
}
diff --git a/core/vendor/filemanager/upload.php b/core/vendor/filemanager/upload.php
index 639f51d7..48087eca 100644
--- a/core/vendor/filemanager/upload.php
+++ b/core/vendor/filemanager/upload.php
@@ -50,8 +50,21 @@ try {
$cycle = false;
}
if (file_exists($path . "config.php")) {
+ $configMain = $config;
$configTemp = include $path . 'config.php';
- $config = array_merge($config, $configTemp);
+ if(is_array($configTemp) && count($configTemp) > 0){
+ $config = array_merge($configMain, $configTemp);
+ $config['ext'] = array_merge(
+ $config['ext_img'],
+ $config['ext_file'],
+ $config['ext_misc'],
+ $config['ext_video'],
+ $config['ext_music']
+ );
+ }
+ else{
+ $config = $configMain;
+ }
//TODO switch to array
$cycle = false;
}
@@ -63,35 +76,36 @@ try {
if (trans("Upload_error_messages") !== "Upload_error_messages") {
$messages = trans("Upload_error_messages");
}
+ if ($config['url_upload']) {
+ // make sure the length is limited to avoid DOS attacks
+ if (isset($_POST['url']) && strlen($_POST['url']) < 2000) {
+ $url = $_POST['url'];
+ $urlPattern = '/^(https?:\/\/)?([\da-z\.-]+\.[a-z\.]{2,6}|[\d\.]+)([\/?=]{1}[\da-z\.-]+)*[\/\?]?$/i';
- // make sure the length is limited to avoid DOS attacks
- if (isset($_POST['url']) && strlen($_POST['url']) < 2000) {
- $url = $_POST['url'];
- $urlPattern = '/^(https?:\/\/)?([\da-z\.-]+\.[a-z\.]{2,6}|[\d\.]+)([\/?=]{1}[\da-z\.-]+)*[\/\?]?$/i';
+ if (preg_match($urlPattern, $url)) {
+ $temp = tempnam('/tmp', 'RF');
- if (preg_match($urlPattern, $url)) {
- $temp = tempnam('/tmp','RF');
-
- $ch = curl_init($url);
- $fp = fopen($temp, 'wb');
- curl_setopt($ch, CURLOPT_FILE, $fp);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_exec($ch);
- if (curl_errno($ch)) {
+ $ch = curl_init($url);
+ $fp = fopen($temp, 'wb');
+ curl_setopt($ch, CURLOPT_FILE, $fp);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_exec($ch);
+ if (curl_errno($ch)) {
+ curl_close($ch);
+ throw new Exception('Invalid URL');
+ }
curl_close($ch);
- throw new Exception('Invalid URL');
- }
- curl_close($ch);
- fclose($fp);
+ fclose($fp);
- $_FILES['files'] = array(
- 'name' => array(basename($_POST['url'])),
- 'tmp_name' => array($temp),
- 'size' => array(filesize($temp)),
- 'type' => null
- );
- } else {
- throw new Exception('Is not a valid URL.');
+ $_FILES['files'] = array(
+ 'name' => array(basename($_POST['url'])),
+ 'tmp_name' => array($temp),
+ 'size' => array(filesize($temp)),
+ 'type' => null
+ );
+ } else {
+ throw new Exception('Is not a valid URL.');
+ }
}
}
diff --git a/index.php b/index.php
index d1880818..8da6c739 100644
--- a/index.php
+++ b/index.php
@@ -17,6 +17,9 @@
/**
* Initialisation de Zwii
*/
+// Remplace la directive htaccess
+ini_set('session.use_trans_sid', FALSE);
+// Démarre la session
session_start();
/**
diff --git a/module/.htaccess b/module/.htaccess
new file mode 100644
index 00000000..3b355e3e
--- /dev/null
+++ b/module/.htaccess
@@ -0,0 +1,3 @@
+# Bloque l'accès à la librairie
+Order deny,allow
+Deny from all
\ No newline at end of file