From 28b883095c95ba7f49bf0c18cddd637f77e53301 Mon Sep 17 00:00:00 2001 From: magroski Date: Mon, 22 Aug 2022 14:27:11 -0300 Subject: [PATCH] remove dead code --- src/Csv.php | 34 - src/CurlInterface.php | 210 - src/Diff.php | 395 -- src/S3.php | 125 - src/S3/Image.php | 363 -- src/Services/Google/DistanceMatrixAPI.php | 130 - .../DistanceMatrixLocationInvalid.php | 12 - .../ValueObject/DistanceMatrixDestination.php | 80 - .../ValueObject/DistanceMatrixLocation.php | 147 - .../ValueObject/DistanceMatrixOrigin.php | 62 - .../ValueObject/DistanceMatrixResponse.php | 124 - src/Sms.php | 53 - src/Sms/Twilio.php | 126 - src/Sms/Tww.php | 139 - src/TextParser.php | 540 -- src/Time.php | 249 - src/Time/DateInterval.php | 78 - src/Upload.php | 5270 ----------------- src/Validator.php | 135 - .../Google/DistanceMatrixLocationTest.php | 83 - tests/Time/DateIntervalTest.php | 57 - tests/TimeTest.php | 74 - tests/ValidatorTest.php | 42 - 23 files changed, 8528 deletions(-) delete mode 100644 src/Csv.php delete mode 100644 src/CurlInterface.php delete mode 100644 src/Diff.php delete mode 100644 src/S3.php delete mode 100644 src/S3/Image.php delete mode 100644 src/Services/Google/DistanceMatrixAPI.php delete mode 100644 src/Services/Google/Exception/DistanceMatrixLocationInvalid.php delete mode 100644 src/Services/Google/ValueObject/DistanceMatrixDestination.php delete mode 100644 src/Services/Google/ValueObject/DistanceMatrixLocation.php delete mode 100644 src/Services/Google/ValueObject/DistanceMatrixOrigin.php delete mode 100644 src/Services/Google/ValueObject/DistanceMatrixResponse.php delete mode 100644 src/Sms.php delete mode 100644 src/Sms/Twilio.php delete mode 100644 src/Sms/Tww.php delete mode 100644 src/TextParser.php delete mode 100644 src/Time.php delete mode 100644 src/Time/DateInterval.php delete mode 100644 src/Upload.php delete mode 100644 src/Validator.php delete mode 100644 tests/Services/Google/DistanceMatrixLocationTest.php delete mode 100644 tests/Time/DateIntervalTest.php delete mode 100644 tests/TimeTest.php delete mode 100644 tests/ValidatorTest.php diff --git a/src/Csv.php b/src/Csv.php deleted file mode 100644 index 32a7103..0000000 --- a/src/Csv.php +++ /dev/null @@ -1,34 +0,0 @@ -insertAll($list); //using an array - } - - static function addVal(&$line, $value) - { - $line[] = utf8_decode($value); - } -} diff --git a/src/CurlInterface.php b/src/CurlInterface.php deleted file mode 100644 index bccc61d..0000000 --- a/src/CurlInterface.php +++ /dev/null @@ -1,210 +0,0 @@ -authType = $authType; - $this->authParam = $authParam; - } - - /** - * Send a POST request with its data encoded as JSON - * - * @param string $url Url to call - * @param array $data Key-value array to be json_encoded - * @param array $dataQuery Key-value array to be json_encoded - * - * @return string request result - */ - public function postJson(string $url, $data = [], $dataQuery = []) - { - $query = http_build_query($dataQuery); - $ch = curl_init($url . '?' . $query); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if ($this->authType == self::BASIC) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } else { - if ($this->authType == self::SAFE) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } - } - $result = curl_exec($ch); - curl_close($ch); - - return $result; - } - - /** - * Send a POST request with its data as PARAMS - * Ex: example.com/my-route/{param}/{param2} - * - * @param string $url Url to call - * @param array $data Simple array with params to be passed - * @param array $dataQuery Key-value array to be json_encoded - * - * @return string request result - */ - public function postUrl(string $url, $data = [], $dataQuery = []) - { - $params = implode('/', $data); - $query = http_build_query($dataQuery); - $ch = curl_init($url . $params . '?' . $query); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if ($this->authType == self::BASIC) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } else { - if ($this->authType == self::SAFE) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } - } - $result = curl_exec($ch); - curl_close($ch); - - return $result; - } - - /** - * Send a GET request with its data as PARAMS - * Ex: example.com/route/{data} - * - * @param string $url Url to call - * @param array $data Simple array with params to be passed - * @param array $dataQuery Key-value array to be json_encoded - * - * @return string request result - */ - public function getUrl(string $url, $data = [], $dataQuery = []) - { - $params = implode('/', $data); - $query = http_build_query($dataQuery); - $ch = curl_init($url . $params . '?' . $query); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if ($this->authType == self::BASIC) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } else { - if ($this->authType == self::SAFE) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } - } - $result = curl_exec($ch); - curl_close($ch); - - return $result; - } - - /** - * Send a GET request with its data as QUERY - * Ex: example.com/route?x=123&y=456 - * - * @param string $url Url to call - * @param array $data Key-value array with params - * @param array $dataQuery Key-value array to be json_encoded - * - * @return string request result - */ - public function getQuery(string $url, $data = [], $dataQuery = []) - { - $data = array_merge($data, $dataQuery); - $ch = curl_init($url . '?' . http_build_query($data)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if ($this->authType == self::BASIC) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } else { - if ($this->authType == self::SAFE) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } - } - $result = curl_exec($ch); - curl_close($ch); - - return $result; - } - - /** - * Send a DELETE request with its data as PARAMS - * - * @param string $url Url to call - * @param array $data Simple array with params to be passed - * @param array $dataQuery Key-value array to be json_encoded - * - * @return string request result - */ - public function deleteReq(string $url, $data = [], $dataQuery = []) - { - $query = http_build_query($dataQuery); - $params = implode('/', $data); - $ch = curl_init($url . $params . '?' . $query); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if ($this->authType == self::BASIC) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } else { - if ($this->authType == self::SAFE) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } - } - $result = curl_exec($ch); - curl_close($ch); - - return $result; - } - - /** - * Send a PUT request with its data as PARAMS - * - * @param string $url Url to call - * @param array $data Key-value array with params - * @param array $dataQuery Key-value array to be json_encoded - * - * @return string request result - */ - public function putReq(string $url, $data = [], $dataQuery = []) - { - $query = http_build_query($dataQuery); - $ch = curl_init($url . '?' . $query); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if ($this->authType == self::BASIC) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } else { - if ($this->authType == self::SAFE) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_setopt($ch, CURLOPT_USERPWD, $this->authParam); - } - } - $result = curl_exec($ch); - curl_close($ch); - - return $result; - } - -} diff --git a/src/Diff.php b/src/Diff.php deleted file mode 100644 index 656d4c3..0000000 --- a/src/Diff.php +++ /dev/null @@ -1,395 +0,0 @@ -= $start && $end2 >= $start - && $sequence1[$end1] == $sequence2[$end2]) { - $end1--; - $end2--; - } - - // compute the table of longest common subsequence lengths - $table = self::computeTable($sequence1, $sequence2, $start, $end1, $end2); - - // generate the partial diff - $partialDiff = - self::generatePartialDiff($table, $sequence1, $sequence2, $start); - - // generate the full diff - $diff = []; - for ($index = 0; $index < $start; $index++) { - $diff[] = [$sequence1[$index], self::UNMODIFIED]; - } - while (count($partialDiff) > 0) { - $diff[] = array_pop($partialDiff); - } - for ($index = $end1 + 1; - $index < ($compareCharacters ? strlen($sequence1) : count($sequence1)); - $index++) { - $diff[] = [$sequence1[$index], self::UNMODIFIED]; - } - - // return the diff - return $diff; - } - - /* Returns the diff for two files. The parameters are: - * - * $file1 - the path to the first file - * $file2 - the path to the second file - * $compareCharacters - true to compare characters, and false to compare - * lines; this optional parameter defaults to false - */ - public static function compareFiles( - $file1, - $file2, - $compareCharacters = false - ) { - // return the diff of the files - return self::compare( - file_get_contents($file1), - file_get_contents($file2), - $compareCharacters); - } - - /* Returns the table of longest common subsequence lengths for the specified - * sequences. The parameters are: - * - * $sequence1 - the first sequence - * $sequence2 - the second sequence - * $start - the starting index - * $end1 - the ending index for the first sequence - * $end2 - the ending index for the second sequence - */ - private static function computeTable( - $sequence1, - $sequence2, - $start, - $end1, - $end2 - ) { - // determine the lengths to be compared - $length1 = $end1 - $start + 1; - $length2 = $end2 - $start + 1; - - // initialise the table - $table = [array_fill(0, $length2 + 1, 0)]; - - // loop over the rows - for ($index1 = 1; $index1 <= $length1; $index1++) { - // create the new row - $table[$index1] = [0]; - - // loop over the columns - for ($index2 = 1; $index2 <= $length2; $index2++) { - // store the longest common subsequence length - if ($sequence1[$index1 + $start - 1] - == $sequence2[$index2 + $start - 1] - ) { - $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1; - } else { - $table[$index1][$index2] = - max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]); - } - } - } - - // return the table - return $table; - } - - /* Returns the partial diff for the specificed sequences, in reverse order. - * The parameters are: - * - * $table - the table returned by the computeTable function - * $sequence1 - the first sequence - * $sequence2 - the second sequence - * $start - the starting index - */ - private static function generatePartialDiff( - $table, - $sequence1, - $sequence2, - $start - ) { - // initialise the diff - $diff = []; - - // initialise the indices - $index1 = count($table) - 1; - $index2 = count($table[0]) - 1; - - // loop until there are no items remaining in either sequence - while ($index1 > 0 || $index2 > 0) { - // check what has happened to the items at these indices - if ($index1 > 0 && $index2 > 0 - && $sequence1[$index1 + $start - 1] - == $sequence2[$index2 + $start - 1] - ) { - // update the diff and the indices - $diff[] = [$sequence1[$index1 + $start - 1], self::UNMODIFIED]; - $index1--; - $index2--; - } else { - if ($index2 > 0 - && $table[$index1][$index2] == $table[$index1][$index2 - 1] - ) { - // update the diff and the indices - $diff[] = [$sequence2[$index2 + $start - 1], self::INSERTED]; - $index2--; - } else { - // update the diff and the indices - $diff[] = [$sequence1[$index1 + $start - 1], self::DELETED]; - $index1--; - } - } - } - - // return the diff - return $diff; - } - - /* Returns a diff as a string, where unmodified lines are prefixed by ' ', - * deletions are prefixed by '- ', and insertions are prefixed by '+ '. The - * parameters are: - * - * $diff - the diff array - * $separator - the separator between lines; this optional parameter defaults - * to "\n" - */ - public static function toString($diff, $separator = "\n") - { - // initialise the string - $string = ''; - - // loop over the lines in the diff - foreach ($diff as $line) { - // extend the string with the line - switch ($line[1]) { - case self::UNMODIFIED : - $string .= ' ' . $line[0]; - break; - case self::DELETED : - $string .= '- ' . $line[0]; - break; - case self::INSERTED : - $string .= '+ ' . $line[0]; - break; - } - - // extend the string with the separator - $string .= $separator; - } - - // return the string - return $string; - } - - /* Returns a diff as an HTML string, where unmodified lines are contained - * within 'span' elements, deletions are contained within 'del' elements, and - * insertions are contained within 'ins' elements. The parameters are: - * - * $diff - the diff array - * $separator - the separator between lines; this optional parameter defaults - * to '
' - */ - public static function toHTML($diff, $separator = '
') - { - // initialise the HTML - $html = ''; - - // loop over the lines in the diff - foreach ($diff as $line) { - // extend the HTML with the line - switch ($line[1]) { - case self::UNMODIFIED : - $element = 'span'; - break; - case self::DELETED : - $element = 'del'; - break; - case self::INSERTED : - $element = 'ins'; - break; - } - $html .= - '<' . $element . '>' - . htmlspecialchars($line[0]) - . ''; - - // extend the HTML with the separator - $html .= $separator; - } - - // return the HTML - return $html; - } - - /* Returns a diff as an HTML table. The parameters are: - * - * $diff - the diff array - * $indentation - indentation to add to every line of the generated HTML; this - * optional parameter defaults to '' - * $separator - the separator between lines; this optional parameter - * defaults to '
' - */ - public static function toTable($diff, $indentation = '', $separator = '
') - { - // initialise the HTML - $html = $indentation . "\n"; - - // loop over the lines in the diff - $index = 0; - while ($index < count($diff)) { - // determine the line type - switch ($diff[$index][1]) { - // display the content on the left and right - case self::UNMODIFIED: - $leftCell = - self::getCellContent( - $diff, $indentation, $separator, $index, self::UNMODIFIED); - $rightCell = $leftCell; - break; - - // display the deleted on the left and inserted content on the right - case self::DELETED: - $leftCell = - self::getCellContent( - $diff, $indentation, $separator, $index, self::DELETED); - $rightCell = - self::getCellContent( - $diff, $indentation, $separator, $index, self::INSERTED); - break; - - // display the inserted content on the right - case self::INSERTED: - $leftCell = ''; - $rightCell = - self::getCellContent( - $diff, $indentation, $separator, $index, self::INSERTED); - break; - } - - // extend the HTML with the new row - $html .= - $indentation - . " \n" - . $indentation - . ' \n" - . $indentation - . ' \n" - . $indentation - . " \n"; - } - - // return the HTML - return $html . $indentation . "
' - . $leftCell - . "' - . $rightCell - . "
\n"; - } - - /* Returns the content of the cell, for use in the toTable function. The - * parameters are: - * - * $diff - the diff array - * $indentation - indentation to add to every line of the generated HTML - * $separator - the separator between lines - * $index - the current index, passes by reference - * $type - the type of line - */ - private static function getCellContent( - $diff, - $indentation, - $separator, - &$index, - $type - ) { - // initialise the HTML - $html = ''; - - // loop over the matching lines, adding them to the HTML - while ($index < count($diff) && $diff[$index][1] == $type) { - $html .= - '' - . htmlspecialchars($diff[$index][0]) - . '' - . $separator; - $index++; - } - - // return the HTML - return $html; - } - -} diff --git a/src/S3.php b/src/S3.php deleted file mode 100644 index fea3388..0000000 --- a/src/S3.php +++ /dev/null @@ -1,125 +0,0 @@ -obj = new S3Client([ - 'version' => 'latest', - 'region' => 'us-east-1', - 'credentials' => $credentialsInst, - ]); - - $this->bucket_name = $bucket_name; - } - - /** - * - * Upload a file - * - * @param string $source Full path to the file, including the filename - * - * @param bool $path - * @param bool $filename - * @param bool $contentType - * - * @return boolean - */ - public function sendFile($source, $path = false, $filename = false, $contentType = false) - { - $full_path = ''; - $dest_path = ''; - - try { - $filename = ($filename) ? $filename : basename($source); - $filename = $this->sanitizeFilename($filename); - - if ($path) { - $full_path = $this->bucket_name . '/' . $path . '/' . $filename; - $dest_path = $path . '/' . $filename; - } else { - $full_path = $this->bucket_name . '/' . $filename; - $dest_path = $filename; - } - $objectInfo = [ - 'Bucket' => $this->bucket_name, - 'Key' => $dest_path, - 'SourceFile' => $source, - 'ACL' => 'public-read', - ]; - - if ($contentType) { - $objectInfo['ContentType'] = $contentType; - } - $this->obj->putObject($objectInfo); - } catch (\Exception $e) { - error_log($e); - - return false; - } - - return $full_path; - } - - /** - * - * Delete a file - * - * @param string $file_path Url path to the file - * - * @return boolean - */ - public function deleteFile($file_path) - { - try { - $this->obj->deleteObject(['Bucket' => $this->bucket_name, 'Key' => $file_path,]); - } catch (\Exception $e) { - return false; - } - - return true; - } - - /** - * - * Set the bucket name - * - * @param string $bucket_name Bucket name - */ - public function setBucketName($bucket_name) - { - $this->bucket_name = $bucket_name; - } - - /** - * - * Sanitizes the filename removing not allowed characters by Amazon S3 - * - * @param string $file_name Filename - * - * @return string Sanitized filename - */ - public function sanitizeFilename($file_name) - { - return str_replace(["\\", "_", ":", " ", "+"], "-", $file_name); - } -} diff --git a/src/S3/Image.php b/src/S3/Image.php deleted file mode 100644 index 02d86b4..0000000 --- a/src/S3/Image.php +++ /dev/null @@ -1,363 +0,0 @@ -s3 = new S3($accessKey, $secretKey, $bucket); - } - - /** - * Load an image from a form file input - * - * @param bool $name File input name attribute - * - * @return void - - */ - public function getFromInput($name = false) - { - if ($name) { - $this->img = $_FILES[$name]; - $this->handle = new Upload($this->img); - $this->_new_name = $this->s3->sanitizeFilename(uniqid("", true) . $this->handle->file_src_name); - } - } - - /** - * Load an image from a system path - * - * @param bool $name File name - * @param bool $path File path - * - * @return void - - */ - public function getFromPath($name = false, $path = false) - { - if ($path && $name) { - $this->img = $path . '/' . $name; - $this->handle = new Upload($this->img); - $this->_new_name = $this->s3->sanitizeFilename(uniqid("", true) . $this->handle->file_src_name); - } - } - - /** - * Load an image from a given url - * - * @param string $url File url - * @param bool $name Optional name of the destiny file - * - * @return bool - */ - public function getFromURL($url, $name = false) - { - $tmp_path = sys_get_temp_dir() . '/'; - - if (Validator::validate(Validator::V_LINK, $url)) { - $image = getimagesize($url); - switch ($image['mime']) { - case 'image/gif': - case 'image/png': - case 'image/bmp': - case 'image/jpeg': - if ($image['mime'] == 'image/gif') { - $type = '.gif'; - } - if ($image['mime'] == 'image/png') { - $type = '.png'; - } - if ($image['mime'] == 'image/bmp') { - $type = '.bmp'; - } - if ($image['mime'] == 'image/jpeg') { - $type = '.jpg'; - } - - if (!$name) { - $name = uniqid('post-') . $type; - } else { - $name .= '-' . uniqid("", true) . $type; - } - file_put_contents($tmp_path . $name, file_get_contents($url)); - - $this->getFromPath($name, sys_get_temp_dir()); - $this->width = $image[0]; - $this->height = $image[1]; - - return true; - default: - return false; - } - } - - return false; - } - - public function getWidth() - { - return $this->width; - } - - public function getHeight() - { - return $this->height; - } - - public function convertJpeg() - { - $this->handle->image_convert = 'jpeg'; - } - - public function setJpegQuality($quality) - { - $this->convertJpeg(); - $this->handle->jpeg_quality = $quality; - } - - /** - * Returns the image signature - */ - public function getSignature() - { - return puzzle_compress_cvec($this->signature); - } - - /** - * Sets whether the image format will be converted or not - * @param $format - */ - public function setImageConvert($format) - { - $this->handle->image_convert = $format; - } - - /** - * @param mixed $url URL of the image - * @return bool - */ - public static function checkMinImageSize($url) - { - $tmp_path = sys_get_temp_dir() . '/'; - - if (!Validator::validate(Validator::V_LINK, $url)) { - return false; - } - - $image = getimagesize($url); - - return ($image[0] > 100 && $image[1] > 100); - } - - /** - * @param string $filename name of the file - * @param string $path path to the file - * - * @return bool - */ - public function delete($filename, $path) - { - return $this->s3->deleteFile(rtrim($path, '/') . '/' . $filename); - } - - /** - * Sets the file name for the new image - * - * @param $name - */ - public function setName($name) - { - $this->handle->file_dst_name_body = $name; - } - - public function setNewName($name) - { - $this->_new_name = $this->s3->sanitizeFilename($name); - } - - /** - * Save the current image on the desired path - * - * @param string $path File system path to save the image to - */ - public function save($path = 'i') - { - $tmp_path = sys_get_temp_dir() . '/'; - $this->handle->process($tmp_path); - - $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name); - unlink($tmp_path . $this->handle->file_dst_name); - - return $this->_new_name; - } - - /** - * Save the current image with fixed width - * - * @param string $width the width of the new image - * @param string $path File system path to save the image to - */ - public function saveFixedWidth($width, $path = 'i') - { - $this->handle->image_resize = true; - $this->handle->image_ratio_y = true; - $this->handle->image_x = $width; - - $tmp_path = sys_get_temp_dir() . '/'; - $this->handle->process($tmp_path); - - $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name); - unlink($tmp_path . $this->handle->file_dst_name); - - return $this->_new_name; - } - - /** - * Save the current image with fixed height - * - * @param string $height the height of the new image - * @param string $path File system path to save the image to - */ - public function saveFixedHeight($height, $path = 'i') - { - $this->handle->image_resize = true; - $this->handle->image_ratio_x = true; - $this->handle->image_y = $height; - - $tmp_path = sys_get_temp_dir() . '/'; - $this->handle->process($tmp_path); - - $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name); - unlink($tmp_path . $this->handle->file_dst_name); - - return $this->_new_name; - } - - /** - * Save the current image with max width and height keeping ratio - * - * @param int $width max width of the image - * @param int $height max height of the image - * @param string $path File system path to save the image to - */ - public function saveMaxWidthHeight($width, $height = 20000, $path = 'i') - { - $this->handle->image_resize = true; - $this->handle->image_ratio = true; - $this->handle->image_x = $width; - $this->handle->image_y = $height; - - $tmp_path = sys_get_temp_dir() . '/'; - $this->handle->process($tmp_path); - - $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name); - unlink($tmp_path . $this->handle->file_dst_name); - - return $this->_new_name; - } - - /** - * Save the current image with fixed width and height cropping the exceeding. - * - * @param int $width width of the thumbnail - * @param int $height height of the thumbnail - * @param string $path File system path to save the image to - */ - public function saveThumb($width, $height, $path = 'i') - { - $this->handle->image_resize = true; - $this->handle->image_ratio_crop = true; - $this->handle->image_x = $width; - $this->handle->image_y = $height; - - $tmp_path = sys_get_temp_dir() . '/'; - $this->handle->process($tmp_path); - $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name); - unlink($tmp_path . $this->handle->file_dst_name); - - return $this->_new_name; - } - - /** - * Checks whether a file is an image - * - * @param string $name Name of the $_FILES[] field to be checked - * - * @return bool - */ - public static function isImage($name) - { - if (isset($_FILES[$name])) { - $tempFile = $_FILES[$name]['tmp_name']; - if (!empty($tempFile) && file_exists($tempFile)) { - $image = getimagesize($tempFile); - switch ($image['mime']) { - case 'image/gif': - case 'image/png': - case 'image/bmp': - case 'image/tiff': - case 'image/jpeg': - return true; - } - } - } - - if (file_exists($name)) { - $image = getimagesize($name); - switch ($image['mime']) { - case 'image/gif': - case 'image/png': - case 'image/bmp': - case 'image/tiff': - case 'image/jpeg': - return true; - } - } - - return false; - } - - /** - * Returns the image width ans height - * - * @param string $name Name of the $_FILES[] field to be checked - * - * @return array|bool - */ - public static function getImageSize($name) - { - if (isset($_FILES[$name])) { - $tempFile = $_FILES[$name]['tmp_name']; - if (!empty($tempFile) && file_exists($tempFile)) { - $size = getimagesize($tempFile); - - return $size; - } - } - - return getimagesize($name); - } -} diff --git a/src/Services/Google/DistanceMatrixAPI.php b/src/Services/Google/DistanceMatrixAPI.php deleted file mode 100644 index 702e9df..0000000 --- a/src/Services/Google/DistanceMatrixAPI.php +++ /dev/null @@ -1,130 +0,0 @@ -apiKey = $apiKey; - $this->format = 'json'; - } - - /** - * Calculates the distance between multiple origins and destinations - * - * @param DistanceMatrixLocation[] $origins - * @param DistanceMatrixLocation[] $destinations - * - * As Google always return the distance value in meters (not km), the function multiplies - * the result by 0.62 (km:mile) to calculate an approximation in imperial. - * Obs: Be aware that 1 Km = 0.62 miles but 1 meter != 0.62 yards. - * - * @return DistanceMatrixResponse - * @throws ServiceProviderException - */ - public function calculateDistanceMatrix(array $origins, array $destinations) : DistanceMatrixResponse - { - $formattedOrigins = $this->formatEntities($origins); - $formattedDestinations = $this->formatEntities($destinations); - - $query = http_build_query([ - 'origins' => $formattedOrigins, - 'destinations' => $formattedDestinations, - 'key' => $this->apiKey, - ]); - - $url = $this->generateBaseUrl() . '?' . $query; - $data = $this->processRequest($url); - - if (!$this->checkResponseStatus($data)) { - $data = $this->processRequest($url); - if (!$this->checkResponseStatus($data)) { - throw new ServiceProviderException('GoogleDistanceMatrix returned an unknown_error after retry'); - } - } - - if (!array_key_exists('rows', $data)) { - throw new ServiceProviderException('Missing key "rows" on data: ' . print_r($data, true)); - } - - return new DistanceMatrixResponse( - $data['rows'], - explode('|', $formattedOrigins), - explode('|', $formattedDestinations), - $data['origin_addresses'], - $data['destination_addresses'] - ); - } - - private function generateBaseUrl() : string - { - return $this->endpoint . $this->format; - } - - /** - * @param DistanceMatrixLocation[] $entities - * - * @return string - */ - private function formatEntities(array $entities) : string - { - $formattedEntities = array_map(function (DistanceMatrixLocation $entry) { - return $entry->getFormattedLocation(); - }, $entities); - $formattedEntities = implode('|', $formattedEntities); - - return $formattedEntities; - } - - /** - * @throws \Frogg\Exception\ServiceProviderException - */ - private function checkResponseStatus($data) : bool - { - $details = isset($data['error_message']) ? $data['error_message'] : ''; - - switch ($data['status']) { - case 'OK': - return true; - case 'INVALID_REQUEST': - throw new ServiceProviderException('Invalid Request. ' . $details); - case 'MAX_ELEMENTS_EXCEEDED': - throw new ServiceProviderException('Request contains too many elements. ' . $details); - case 'OVER_QUERY_LIMIT': - throw new ServiceProviderException('Too many requests. ' . $details); - case 'REQUEST_DENIED': - throw new ServiceProviderException('Google denied API usage. Check GoogleDistanceMatrix console.' . $details); - //From the docs: - //UNKNOWN_ERROR indicates a Distance Matrix request could not be processed due to a server error. - //The request may succeed if you try again. - case 'UNKNOWN_ERROR'; - return false; - } - - return true; - } - - /** - * @return mixed - */ - private function processRequest(string $url) - { - $response = file_get_contents($url); - $data = json_decode($response, true); - - return $data; - } - -} diff --git a/src/Services/Google/Exception/DistanceMatrixLocationInvalid.php b/src/Services/Google/Exception/DistanceMatrixLocationInvalid.php deleted file mode 100644 index c90b77b..0000000 --- a/src/Services/Google/Exception/DistanceMatrixLocationInvalid.php +++ /dev/null @@ -1,12 +0,0 @@ -origin = $origin; - $this->address = $address; - $this->data = $data; - } - - public function getAddress() : string - { - return $this->address; - } - - public function getDistanceValue(bool $convertToMiles = true) : ?float - { - if (!isset($this->data['distance']['value'])) { - return null; - } - - if ($convertToMiles) { - return $this->data['distance']['value'] * DistanceMatrixAPI::METER_TO_MILE; - } - - return $this->data['distance']['value']; - } - - public function getDistanceText(bool $convertToMiles = true) : ?string - { - if (!isset($this->data['distance']['text'])) { - return null; - } - - if ($convertToMiles) { - return round($this->data['distance']['value'] * DistanceMatrixAPI::METER_TO_MILE, 2) . " miles"; - } - - return $this->data['distance']['text']; - } - - public function getDurationValue() : ?float - { - if (!isset($this->data['duration']['value'])) { - return null; - } - - return $this->data['duration']['value']; - } - - public function getDurationText() : ?string - { - if (!isset($this->data['duration']['text'])) { - return null; - } - - return $this->data['duration']['text']; - } - - public function getOrigin() : DistanceMatrixOrigin - { - return $this->origin; - } -} diff --git a/src/Services/Google/ValueObject/DistanceMatrixLocation.php b/src/Services/Google/ValueObject/DistanceMatrixLocation.php deleted file mode 100644 index f8d47a2..0000000 --- a/src/Services/Google/ValueObject/DistanceMatrixLocation.php +++ /dev/null @@ -1,147 +0,0 @@ -country = $country; - $this->state = $state; - $this->city = $city; - $this->zipCode = $zipCode; - $this->latitude = $latitude; - $this->longitude = $longitude; - $this->placeId = $placeId; - $this->completeAddress = $completeAddress; - - if (!$this->getFormattedLocation()) { - throw new DistanceMatrixLocationInvalid(); - } - } - - public function getZipCode() : string - { - return $this->zipCode; - } - - public function getCountry() : string - { - return $this->country; - } - - public function getState() : string - { - return $this->state; - } - - public function getCity() : string - { - return $this->city; - } - - public function getLatitude() : string - { - return $this->latitude; - } - - public function getLongitude() : string - { - return $this->longitude; - } - - public function getPlaceId() : string - { - return $this->placeId; - } - - public function getFormattedLocation() : ?string - { - if ($this->formattedLocation) { - return $this->formattedLocation; - } - - if ($this->completeAddress) { - return $this->formattedLocation = $this->replaceSpaces($this->completeAddress); - } - - if ($this->latitude && $this->longitude) { - return $this->formattedLocation = "{$this->getLatitude()},{$this->getLongitude()}"; - } - - if ($this->zipCode) { - return $this->formattedLocation = $this->replaceSpaces($this->getZipCode()); - } - - if ($this->placeId) { - return $this->formattedLocation = "place_id:{$this->getPlaceId()}"; - } - - if ($this->city) { - $this->formattedLocation = $this->replaceSpaces($this->getCity()); - } - - if ($this->state) { - $this->concatLocation($this->getState()); - } - - if ($this->country) { - $this->concatLocation($this->getCountry()); - } - - return $this->formattedLocation ?: null; - } - - private function replaceSpaces(string $string) : string - { - return str_replace(" ", "+", $string); - } - - private function concatLocation(string $string) : void - { - if ($this->formattedLocation) { - $this->formattedLocation .= "+"; - } - - $this->formattedLocation .= $this->replaceSpaces($string); - } -} diff --git a/src/Services/Google/ValueObject/DistanceMatrixOrigin.php b/src/Services/Google/ValueObject/DistanceMatrixOrigin.php deleted file mode 100644 index b969228..0000000 --- a/src/Services/Google/ValueObject/DistanceMatrixOrigin.php +++ /dev/null @@ -1,62 +0,0 @@ -index = $index; - $this->address = $address; - $this->destinations = $destinations; - $this->destinationNames = $destinationNames; - } - - public function getAddress() : string - { - return $this->address; - } - - public function getDestination(int $index) : DistanceMatrixDestination - { - if (!isset($this->destinations[$index])) { - return new DistanceMatrixDestination($this, $this->destinationNames[$index], []); - } - - return new DistanceMatrixDestination($this, $this->destinationNames[$index], $this->destinations[$index]); - } - - public function getDestinationByName(string $name) : DistanceMatrixDestination - { - $idx = array_search($name, $this->destinationNames); - - return $this->getDestination($idx); - } - - /** - * @return DistanceMatrixDestination[] - */ - public function getDestinations() : array - { - $result = []; - foreach ($this->destinations as $idx => $destination) { - $result[] = $this->getDestination($idx); - } - - return $result; - } -} diff --git a/src/Services/Google/ValueObject/DistanceMatrixResponse.php b/src/Services/Google/ValueObject/DistanceMatrixResponse.php deleted file mode 100644 index 71e74b1..0000000 --- a/src/Services/Google/ValueObject/DistanceMatrixResponse.php +++ /dev/null @@ -1,124 +0,0 @@ -rows = $rows; - $this->origins = $origins; - $this->destinations = $destinations; - $this->googleOrigins = $googleOrigins; - $this->googleDestinations = $googleDestinations; - } - - /** - * @return mixed[] - */ - public function getResponseData() : array - { - return $this->rows; - } - - /** - * @return mixed[] - */ - public function getOrigins() : array - { - return $this->origins; - } - - /** - * @return mixed[] - */ - public function getDestinations() : array - { - return $this->destinations; - } - - /** - * @return mixed[] - */ - public function getGoogleOrigins() : array - { - return $this->googleOrigins; - } - - /** - * @return mixed[] - */ - public function getGoogleDestinations() : array - { - return $this->googleDestinations; - } - - public function hasOrigin(int $index) : bool - { - return isset($this->rows[$index]['elements']); - } - - public function hasDestination(int $originIndex, int $destinationIndex) : bool - { - return isset($this->rows[$originIndex]['elements'][$destinationIndex]); - } - - public function getOrigin(int $index) : DistanceMatrixOrigin - { - if (!$this->hasOrigin($index)) { - return new DistanceMatrixOrigin($index, $this->origins[$index], [], $this->destinations); - } - - return new DistanceMatrixOrigin($index, $this->origins[$index], $this->rows[$index]['elements'], $this->destinations); - } - - public function getOriginByName(string $name) : DistanceMatrixOrigin - { - $idx = array_search($name, $this->origins); - - return $this->getOrigin($idx); - } - - public function getDestinationByName(string $originName, string $destinationName) : DistanceMatrixDestination - { - $origin = $this->getOriginByName($originName); - $destinationIdx = array_search($destinationName, $this->destinations); - - return $origin->getDestination($destinationIdx); - } - - public function getDestination(int $originIndex, int $destinationIndex) : DistanceMatrixDestination - { - return $this->getOrigin($originIndex)->getDestination($destinationIndex); - } -} diff --git a/src/Sms.php b/src/Sms.php deleted file mode 100644 index fbd4175..0000000 --- a/src/Sms.php +++ /dev/null @@ -1,53 +0,0 @@ -gateway = new Twilio($credentials); - break; - case 'br': - $this->gateway = new Tww($credentials); - break; - default: - $this->gateway = new Twilio($credentials); - break; - } - } - - /** - * Send a sms - * - * @param array $data ['id', 'text', 'to', 'from'] Key-value array - * * 'id' - recipient unique identifier - * * 'text' - message that will be sent - * * 'to' - number without country code, - * * 'from' - number that will send the message, - * - * @return bool - * @throws \Exception - */ - public function send(array $data) - { - return $this->gateway->send($data); - } - -} diff --git a/src/Sms/Twilio.php b/src/Sms/Twilio.php deleted file mode 100644 index b4809cb..0000000 --- a/src/Sms/Twilio.php +++ /dev/null @@ -1,126 +0,0 @@ -x,'TWILIO_AUTH_TOKEN'=>y] - */ - public function __construct(array $credentials) - { - $this->client = new Client($credentials['TWILIO_ACCOUNT_ID'], $credentials['TWILIO_AUTH_TOKEN']); - } - - /** - * Send a sms using Twilio Rest API - * - * @param array $data ['text', 'to', 'from'] Key-value array - * * 'text' - message that will be sent - * * 'to' - number without country code, - * * 'from' - number that will send the message, - * - * @return bool - */ - public function send(array $data) - { - $text = self::sanitizeText($data['text']); - $to = preg_replace("/[(,),\-,\s]/", "", $data['to']); - $from = preg_replace("/[(,),\-,\s]/", "", $data['from']); - - $this->client->messages->create($to, ['from' => $from, 'body' => $text]); - - return true; - } - - /** - * Swap incompatible characters with compatible ones. - * Ex: Swaps [ã | à | á] with [a] - * - * @param string $text Text to be sanitized - * - * @return string Sanitized text. - */ - public static function sanitizeText(string $text) - { - $unwanted_array = [ - 'Š' => 'S', - 'š' => 's', - 'Ž' => 'Z', - 'ž' => 'z', - 'À' => 'A', - 'Á' => 'A', - 'Â' => 'A', - 'Ã' => 'A', - 'Ä' => 'A', - 'Å' => 'A', - 'Æ' => 'A', - 'Ç' => 'C', - 'È' => 'E', - 'É' => 'E', - 'Ê' => 'E', - 'Ë' => 'E', - 'Ì' => 'I', - 'Í' => 'I', - 'Î' => 'I', - 'Ï' => 'I', - 'Ñ' => 'N', - 'Ò' => 'O', - 'Ó' => 'O', - 'Ô' => 'O', - 'Õ' => 'O', - 'Ö' => 'O', - 'Ø' => 'O', - 'Ù' => 'U', - 'Ú' => 'U', - 'Û' => 'U', - 'Ü' => 'U', - 'Ý' => 'Y', - 'Þ' => 'B', - 'ß' => 'Ss', - 'à' => 'a', - 'á' => 'a', - 'â' => 'a', - 'ã' => 'a', - 'ä' => 'a', - 'å' => 'a', - 'æ' => 'a', - 'ç' => 'c', - 'è' => 'e', - 'é' => 'e', - 'ê' => 'e', - 'ë' => 'e', - 'ì' => 'i', - 'í' => 'i', - 'î' => 'i', - 'ï' => 'i', - 'ð' => 'o', - 'ñ' => 'n', - 'ò' => 'o', - 'ó' => 'o', - 'ô' => 'o', - 'õ' => 'o', - 'ö' => 'o', - 'ø' => 'o', - 'ù' => 'u', - 'ú' => 'u', - 'û' => 'u', - 'ý' => 'y', - 'þ' => 'b', - 'ÿ' => 'y', - ]; - - return strtr($text, $unwanted_array); - } -} diff --git a/src/Sms/Tww.php b/src/Sms/Tww.php deleted file mode 100644 index 26c8fe0..0000000 --- a/src/Sms/Tww.php +++ /dev/null @@ -1,139 +0,0 @@ -x,'TWW_PASS'=>y] - */ - public function __construct(array $credentials) - { - $this->credentials = ['NumUsu' => $credentials['TWW_USER'], 'Senha' => $credentials['TWW_PASS']]; - } - - /** - * Send a sms using Tww API - * - * @param array $data ['id', 'text', 'to'] Key-value array - * * 'id' - recipient unique identifier - * * 'text' - message that will be sent - * * 'to' - number without country code, - * - * @return bool|string - */ - public function send(array $data) - { - $phone = preg_replace("/[(,),\-,\s]/", "", $data['to']); - $phone = preg_replace('/^' . preg_quote('+55', '/') . '/', '', $phone); - - $text = self::sanitizeText($data['text']); - $url = 'http://webservices.twwwireless.com.br/reluzcap/wsreluzcap.asmx/EnviaSMS'; - $queryData = array_merge($this->credentials, ['Celular' => $phone, 'Mensagem' => $text]); - - if (isset($data['id'])) { - $queryData['SeuNum'] = $data['id']; - } else { - $queryData['SeuNum'] = 0; - } - - $options = [ - 'http' => [ - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", - 'method' => 'POST', - 'content' => http_build_query($queryData), - ], - ]; - $context = stream_context_create($options); - - return file_get_contents($url, false, $context); - } - - /** - * Swap incompatible characters with compatible ones. - * Ex: Swaps [ã | à | á] with [a] - * - * @param string $text Text to be sanitized - * - * @return string Sanitized text. - */ - public static function sanitizeText(string $text) - { - $unwanted_array = [ - 'Š' => 'S', - 'š' => 's', - 'Ž' => 'Z', - 'ž' => 'z', - 'À' => 'A', - 'Á' => 'A', - 'Â' => 'A', - 'Ã' => 'A', - 'Ä' => 'A', - 'Å' => 'A', - 'Æ' => 'A', - 'Ç' => 'C', - 'È' => 'E', - 'É' => 'E', - 'Ê' => 'E', - 'Ë' => 'E', - 'Ì' => 'I', - 'Í' => 'I', - 'Î' => 'I', - 'Ï' => 'I', - 'Ñ' => 'N', - 'Ò' => 'O', - 'Ó' => 'O', - 'Ô' => 'O', - 'Õ' => 'O', - 'Ö' => 'O', - 'Ø' => 'O', - 'Ù' => 'U', - 'Ú' => 'U', - 'Û' => 'U', - 'Ü' => 'U', - 'Ý' => 'Y', - 'Þ' => 'B', - 'ß' => 'Ss', - 'à' => 'a', - 'á' => 'a', - 'â' => 'a', - 'ã' => 'a', - 'ä' => 'a', - 'å' => 'a', - 'æ' => 'a', - 'ç' => 'c', - 'è' => 'e', - 'é' => 'e', - 'ê' => 'e', - 'ë' => 'e', - 'ì' => 'i', - 'í' => 'i', - 'î' => 'i', - 'ï' => 'i', - 'ð' => 'o', - 'ñ' => 'n', - 'ò' => 'o', - 'ó' => 'o', - 'ô' => 'o', - 'õ' => 'o', - 'ö' => 'o', - 'ø' => 'o', - 'ù' => 'u', - 'ú' => 'u', - 'û' => 'u', - 'ý' => 'y', - 'þ' => 'b', - 'ÿ' => 'y', - ]; - - return strtr($text, $unwanted_array); - } -} diff --git a/src/TextParser.php b/src/TextParser.php deleted file mode 100644 index 1c01eff..0000000 --- a/src/TextParser.php +++ /dev/null @@ -1,540 +0,0 @@ - 'A', - chr(195) . chr(129) => 'A', - chr(195) . chr(130) => 'A', - chr(195) . chr(131) => 'A', - chr(195) . chr(132) => 'A', - chr(195) . chr(133) => 'A', - chr(195) . chr(135) => 'C', - chr(195) . chr(136) => 'E', - chr(195) . chr(137) => 'E', - chr(195) . chr(138) => 'E', - chr(195) . chr(139) => 'E', - chr(195) . chr(140) => 'I', - chr(195) . chr(141) => 'I', - chr(195) . chr(142) => 'I', - chr(195) . chr(143) => 'I', - chr(195) . chr(145) => 'N', - chr(195) . chr(146) => 'O', - chr(195) . chr(147) => 'O', - chr(195) . chr(148) => 'O', - chr(195) . chr(149) => 'O', - chr(195) . chr(150) => 'O', - chr(195) . chr(153) => 'U', - chr(195) . chr(154) => 'U', - chr(195) . chr(155) => 'U', - chr(195) . chr(156) => 'U', - chr(195) . chr(157) => 'Y', - chr(195) . chr(159) => 's', - chr(195) . chr(160) => 'a', - chr(195) . chr(161) => 'a', - chr(195) . chr(162) => 'a', - chr(195) . chr(163) => 'a', - chr(195) . chr(164) => 'a', - chr(195) . chr(165) => 'a', - chr(195) . chr(167) => 'c', - chr(195) . chr(168) => 'e', - chr(195) . chr(169) => 'e', - chr(195) . chr(170) => 'e', - chr(195) . chr(171) => 'e', - chr(195) . chr(172) => 'i', - chr(195) . chr(173) => 'i', - chr(195) . chr(174) => 'i', - chr(195) . chr(175) => 'i', - chr(195) . chr(177) => 'n', - chr(195) . chr(178) => 'o', - chr(195) . chr(179) => 'o', - chr(195) . chr(180) => 'o', - chr(195) . chr(181) => 'o', - chr(195) . chr(182) => 'o', - chr(195) . chr(182) => 'o', - chr(195) . chr(185) => 'u', - chr(195) . chr(186) => 'u', - chr(195) . chr(187) => 'u', - chr(195) . chr(188) => 'u', - chr(195) . chr(189) => 'y', - chr(195) . chr(191) => 'y', - // Decompositions for Latin Extended-A - chr(196) . chr(128) => 'A', - chr(196) . chr(129) => 'a', - chr(196) . chr(130) => 'A', - chr(196) . chr(131) => 'a', - chr(196) . chr(132) => 'A', - chr(196) . chr(133) => 'a', - chr(196) . chr(134) => 'C', - chr(196) . chr(135) => 'c', - chr(196) . chr(136) => 'C', - chr(196) . chr(137) => 'c', - chr(196) . chr(138) => 'C', - chr(196) . chr(139) => 'c', - chr(196) . chr(140) => 'C', - chr(196) . chr(141) => 'c', - chr(196) . chr(142) => 'D', - chr(196) . chr(143) => 'd', - chr(196) . chr(144) => 'D', - chr(196) . chr(145) => 'd', - chr(196) . chr(146) => 'E', - chr(196) . chr(147) => 'e', - chr(196) . chr(148) => 'E', - chr(196) . chr(149) => 'e', - chr(196) . chr(150) => 'E', - chr(196) . chr(151) => 'e', - chr(196) . chr(152) => 'E', - chr(196) . chr(153) => 'e', - chr(196) . chr(154) => 'E', - chr(196) . chr(155) => 'e', - chr(196) . chr(156) => 'G', - chr(196) . chr(157) => 'g', - chr(196) . chr(158) => 'G', - chr(196) . chr(159) => 'g', - chr(196) . chr(160) => 'G', - chr(196) . chr(161) => 'g', - chr(196) . chr(162) => 'G', - chr(196) . chr(163) => 'g', - chr(196) . chr(164) => 'H', - chr(196) . chr(165) => 'h', - chr(196) . chr(166) => 'H', - chr(196) . chr(167) => 'h', - chr(196) . chr(168) => 'I', - chr(196) . chr(169) => 'i', - chr(196) . chr(170) => 'I', - chr(196) . chr(171) => 'i', - chr(196) . chr(172) => 'I', - chr(196) . chr(173) => 'i', - chr(196) . chr(174) => 'I', - chr(196) . chr(175) => 'i', - chr(196) . chr(176) => 'I', - chr(196) . chr(177) => 'i', - chr(196) . chr(178) => 'IJ', - chr(196) . chr(179) => 'ij', - chr(196) . chr(180) => 'J', - chr(196) . chr(181) => 'j', - chr(196) . chr(182) => 'K', - chr(196) . chr(183) => 'k', - chr(196) . chr(184) => 'k', - chr(196) . chr(185) => 'L', - chr(196) . chr(186) => 'l', - chr(196) . chr(187) => 'L', - chr(196) . chr(188) => 'l', - chr(196) . chr(189) => 'L', - chr(196) . chr(190) => 'l', - chr(196) . chr(191) => 'L', - chr(197) . chr(128) => 'l', - chr(197) . chr(129) => 'L', - chr(197) . chr(130) => 'l', - chr(197) . chr(131) => 'N', - chr(197) . chr(132) => 'n', - chr(197) . chr(133) => 'N', - chr(197) . chr(134) => 'n', - chr(197) . chr(135) => 'N', - chr(197) . chr(136) => 'n', - chr(197) . chr(137) => 'N', - chr(197) . chr(138) => 'n', - chr(197) . chr(139) => 'N', - chr(197) . chr(140) => 'O', - chr(197) . chr(141) => 'o', - chr(197) . chr(142) => 'O', - chr(197) . chr(143) => 'o', - chr(197) . chr(144) => 'O', - chr(197) . chr(145) => 'o', - chr(197) . chr(146) => 'OE', - chr(197) . chr(147) => 'oe', - chr(197) . chr(148) => 'R', - chr(197) . chr(149) => 'r', - chr(197) . chr(150) => 'R', - chr(197) . chr(151) => 'r', - chr(197) . chr(152) => 'R', - chr(197) . chr(153) => 'r', - chr(197) . chr(154) => 'S', - chr(197) . chr(155) => 's', - chr(197) . chr(156) => 'S', - chr(197) . chr(157) => 's', - chr(197) . chr(158) => 'S', - chr(197) . chr(159) => 's', - chr(197) . chr(160) => 'S', - chr(197) . chr(161) => 's', - chr(197) . chr(162) => 'T', - chr(197) . chr(163) => 't', - chr(197) . chr(164) => 'T', - chr(197) . chr(165) => 't', - chr(197) . chr(166) => 'T', - chr(197) . chr(167) => 't', - chr(197) . chr(168) => 'U', - chr(197) . chr(169) => 'u', - chr(197) . chr(170) => 'U', - chr(197) . chr(171) => 'u', - chr(197) . chr(172) => 'U', - chr(197) . chr(173) => 'u', - chr(197) . chr(174) => 'U', - chr(197) . chr(175) => 'u', - chr(197) . chr(176) => 'U', - chr(197) . chr(177) => 'u', - chr(197) . chr(178) => 'U', - chr(197) . chr(179) => 'u', - chr(197) . chr(180) => 'W', - chr(197) . chr(181) => 'w', - chr(197) . chr(182) => 'Y', - chr(197) . chr(183) => 'y', - chr(197) . chr(184) => 'Y', - chr(197) . chr(185) => 'Z', - chr(197) . chr(186) => 'z', - chr(197) . chr(187) => 'Z', - chr(197) . chr(188) => 'z', - chr(197) . chr(189) => 'Z', - chr(197) . chr(190) => 'z', - chr(197) . chr(191) => 's', - ]; - - $string = strtr($string, $chars); - - return $string; - } - - static function email($email) - { - $normalizeChars = [ - 'Á' => 'A', - 'À' => 'A', - 'Â' => 'A', - 'Ã' => 'A', - 'Å' => 'A', - 'Ä' => 'A', - 'Æ' => 'AE', - 'Ç' => 'C', - 'É' => 'E', - 'È' => 'E', - 'Ê' => 'E', - 'Ë' => 'E', - 'Í' => 'I', - 'Ì' => 'I', - 'Î' => 'I', - 'Ï' => 'I', - 'Ð' => 'Eth', - 'Ñ' => 'N', - 'Ó' => 'O', - 'Ò' => 'O', - 'Ô' => 'O', - 'Õ' => 'O', - 'Ö' => 'O', - 'Ø' => 'O', - 'Ú' => 'U', - 'Ù' => 'U', - 'Û' => 'U', - 'Ü' => 'U', - 'Ý' => 'Y', - - 'á' => 'a', - 'à' => 'a', - 'â' => 'a', - 'ã' => 'a', - 'å' => 'a', - 'ä' => 'a', - 'æ' => 'ae', - 'ç' => 'c', - 'é' => 'e', - 'è' => 'e', - 'ê' => 'e', - 'ë' => 'e', - 'í' => 'i', - 'ì' => 'i', - 'î' => 'i', - 'ï' => 'i', - 'ð' => 'eth', - 'ñ' => 'n', - 'ó' => 'o', - 'ò' => 'o', - 'ô' => 'o', - 'õ' => 'o', - 'ö' => 'o', - 'ø' => 'o', - 'ú' => 'u', - 'ù' => 'u', - 'û' => 'u', - 'ü' => 'u', - 'ý' => 'y', - - 'ß' => 'sz', - 'þ' => 'thorn', - 'ÿ' => 'y', - ]; - - return strtr($email, $normalizeChars); - } - - static function normalize($email) - { - $normalizeChars = [ - 'Á' => 'A', - 'À' => 'A', - 'Â' => 'A', - 'Ã' => 'A', - 'Å' => 'A', - 'Ä' => 'A', - 'Æ' => 'AE', - 'Ç' => 'C', - 'É' => 'E', - 'È' => 'E', - 'Ê' => 'E', - 'Ë' => 'E', - 'Í' => 'I', - 'Ì' => 'I', - 'Î' => 'I', - 'Ï' => 'I', - 'Ð' => 'Eth', - 'Ñ' => 'N', - 'Ó' => 'O', - 'Ò' => 'O', - 'Ô' => 'O', - 'Õ' => 'O', - 'Ö' => 'O', - 'Ø' => 'O', - 'Ú' => 'U', - 'Ù' => 'U', - 'Û' => 'U', - 'Ü' => 'U', - 'Ý' => 'Y', - - 'á' => 'a', - 'à' => 'a', - 'â' => 'a', - 'ã' => 'a', - 'å' => 'a', - 'ä' => 'a', - 'æ' => 'ae', - 'ç' => 'c', - 'é' => 'e', - 'è' => 'e', - 'ê' => 'e', - 'ë' => 'e', - 'í' => 'i', - 'ì' => 'i', - 'î' => 'i', - 'ï' => 'i', - 'ð' => 'eth', - 'ñ' => 'n', - 'ó' => 'o', - 'ò' => 'o', - 'ô' => 'o', - 'õ' => 'o', - 'ö' => 'o', - 'ø' => 'o', - 'ú' => 'u', - 'ù' => 'u', - 'û' => 'u', - 'ü' => 'u', - 'ý' => 'y', - - 'ß' => 'sz', - 'þ' => 'thorn', - 'ÿ' => 'y', - ]; - - return strtr($email, $normalizeChars); - } - - static function toUpper($string) - { - return strtr(strtoupper($string), [ - "à" => "À", - "â" => "Â", - "á" => "Á", - 'ã' => 'Ã', - 'å' => 'Å', - 'ä' => 'Ä', - "è" => "È", - "é" => "É", - "ê" => "Ê", - 'ë' => 'Ë', - "ì" => "Ì", - "î" => "Î", - "í" => "Í", - 'ï' => 'Ï', - "ò" => "Ò", - "ô" => "Ô", - "ó" => "Ó", - 'õ' => 'Õ', - 'ö' => 'Ö', - "ú" => "Ú", - "ù" => "Ù", - "û" => "Û", - 'ü' => 'Ü', - 'ý' => 'Ý', - "ç" => "Ç", - ] - ); - } - - static function strip_urls($str) - { - return preg_replace('|https?://(www\.)?[a-z\.0-9\\\\\\/?=&\-_\+]+|i', '', $str); - } - - static function prepareTags($str, $max = 20) - { - $str = self::removeHTMLSpecialChars($str); - $str = strip_tags($str); - - $quotes = [ - "\xC2\xAB" => '"', // « (U+00AB) in UTF-8 - "\xC2\xBB" => '"', // » (U+00BB) in UTF-8 - "\xE2\x80\x98" => "'", // ‘ (U+2018) in UTF-8 - "\xE2\x80\x99" => "'", // ’ (U+2019) in UTF-8 - "\xE2\x80\x9A" => "'", // ‚ (U+201A) in UTF-8 - "\xE2\x80\x9B" => "'", // ‛ (U+201B) in UTF-8 - "\xE2\x80\x9C" => '"', // “ (U+201C) in UTF-8 - "\xE2\x80\x9D" => '"', // ” (U+201D) in UTF-8 - "\xE2\x80\x9E" => '"', // „ (U+201E) in UTF-8 - "\xE2\x80\x9F" => '"', // ‟ (U+201F) in UTF-8 - "\xE2\x80\xB9" => "'", // ‹ (U+2039) in UTF-8 - "\xE2\x80\xBA" => "'", // › (U+203A) in UTF-8 - ]; - $str = strtr($str, $quotes); - - $a = [ - '/ +/' => ' ', - '/[^ÂÀÁÄÃâãàáäÊÈÉËêèéëÎÍÌÏîíìïÔÕÒÓÖôõòóöÛÙÚÜûúùüÇça-zA-Z0-9\\-, ]/' => '', - '/-+/' => '-', - '/“/' => '"', - '/”/' => '"', - '/, /' => ',', - '/ ,/' => ',', - '/,+/' => ',', - '/^,/' => '', - '/,$/' => '', - ]; - - $tags = explode(',', preg_replace(array_keys($a), array_values($a), $str)); - - return array_unique($tags); - } - - static public function truncate($text, $length = 150, $ending = '...', $exact = false, $considerHtml = false) - { - if ($considerHtml) { - if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { - return $text; - } - - preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); - - $total_length = strlen($ending); - $open_tags = []; - $truncate = ''; - - foreach ($lines as $line_matchings) { - if (!empty($line_matchings[1])) { - if (preg_match('/^<(s*.+?/s*|s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(s.+?)?)>$/is', $line_matchings[1])) { - } else { - if (preg_match('/^$/s', $line_matchings[1], $tag_matchings)) { - $pos = array_search($tag_matchings[1], $open_tags); - if ($pos !== false) { - unset($open_tags[$pos]); - } - } else { - if (preg_match('/^!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { - array_unshift($open_tags, strtolower($tag_matchings[1])); - } - } - } - $truncate .= $line_matchings[1]; - } - $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); - if ($total_length + $content_length > $length) { - $left = $length - $total_length; - $entities_length = 0; - if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { - foreach ($entities[0] as $entity) { - if ($entity[1] + 1 - $entities_length <= $left) { - $left--; - $entities_length += strlen($entity[0]); - } else { - break; - } - } - } - $truncate .= substr($line_matchings[2], 0, $left + $entities_length); - break; - } else { - $truncate .= $line_matchings[2]; - $total_length += $content_length; - } - if ($total_length >= $length) { - break; - } - } - } else { - if (strlen($text) <= $length) { - return $text; - } else { - $truncate = substr($text, 0, $length - strlen($ending)); - } - } - - if (!$exact) { - $spacepos = strrpos($truncate, ' '); - if (isset($spacepos)) { - $truncate = substr($truncate, 0, $spacepos); - } - } - $truncate .= $ending; - - if ($considerHtml) { - foreach ($open_tags as $tag) { - $truncate .= ''; - } - } - - return $truncate; - } - - static function removeHTMLSpecialChars($str) - { - return preg_replace("/&#?[a-z0-9]+;/i", "", $str); - } - - static function prepareHeadline($headline) - { - $a = [ - '/ +/' => ' ', - '/\?+/' => '?', - '/\.+/' => '.', - '/-+/' => '-', - '/!+/' => '!', - ]; - - return strip_tags(htmlspecialchars(trim(preg_replace(array_keys($a), array_values($a), $headline), " \r\n"))); - } - -} diff --git a/src/Time.php b/src/Time.php deleted file mode 100644 index 765e47f..0000000 --- a/src/Time.php +++ /dev/null @@ -1,249 +0,0 @@ -time = ($time) ? $time : time(); - } else { - $date = new \DateTime($time); - $this->time = mktime($date->format('H'), $date->format('i'), $date->format('s'), $date->format('n'), $date->format('d'), $date->format('Y')); - } - } - - /** - * Returns the date formatted as an Unix timestamp - */ - public function __toString() : string - { - return $this->getUnixTstamp() . ''; - } - - /** - * Returns the date formatted as an Unix timestamp - */ - public function getUnixTstamp() : int - { - return $this->time; - } - - /** - * Returns the date formatted as a database timestamp (yyyy-mm-dd hh:ii:ss) - */ - public function getTstamp() : string - { - return $this->getYear() . '-' . $this->getMonth() . '-' . $this->getDay() . ' ' . $this->getHours() . ':' . $this->getMinutes() . ':' . $this->getSeconds(); - } - - /** - * Returns the year of the stored time variable - */ - public function getYear() : string - { - return date('Y', $this->time); - } - - /** - * Returns the month of the stored time variable
- * Value between 01 and 12 (with leading zeros) - */ - public function getMonth() : string - { - return date('m', $this->time); - } - - /** - * Returns the day of the month of the stored time variable
- * Value between 01 and 31 (with leading zeros) - */ - public function getDay() : string - { - return date('d', $this->time); - } - - /** - * Returns the day of the month of the stored time variable
- * Value between 1 and 31 (without leading zeros) - */ - public function getDayNoZero() : string - { - return date('j', $this->time); - } - - /** - * Returns the hour of the day of the stored time variable
- * Value between 00 and 23 (with leading zeros) - */ - public function getHours() : string - { - return date('H', $this->time); - } - - /** - * Returns the minute of the hour of the stored time variable
- * Value between 00 and 59 (with leading zeros) - * - * @return string Date minute as string - */ - public function getMinutes() : string - { - return date('i', $this->time); - } - - /** - * Returns the seconds of the minute of the stored time variable
- * Value between 00 and 59 (with leading zeros) - */ - public function getSeconds() : string - { - return date('s', $this->time); - } - - /** - * Adds time to the stored time variable - * - * @param $seconds int Desired quantity of seconds to add to the current time - * - * @return Time - * - */ - public function add(int $seconds) : self - { - $this->time += $seconds; - - return $this; - } - - /** - * Subtracts time from the stored time variable - * - * @param int $seconds Desired quantity of seconds to subtract from the current time - * - * @return Time - */ - public function subtract(int $seconds) : self - { - $this->time -= $seconds; - - return $this; - } - - /** - * Calculates the absolute difference between the stored time and the $time parameter
- * Returns a {@link DateInterval} object representing the time difference - * - * @param mixed $time Unix timestamp OR a string timestamp (YYYY-MM-DD) - * - * @return DateInterval - */ - public function diff($time) : DateInterval - { - $tmp = new self($time); - - return new DateInterval(abs($this->time - $tmp->getUnixTstamp())); - } - - /** - * This method transforms the stored time variable in a string according to the informed mask
- * Ex: Mask -> 'Y/m/d % H' results in '2010/02/15 % 02' - * - * @param string $mask String mask that will be used to format the time.

- * Y-> 2010
- * y-> 10
- * m-> 02
- * M-> Feb
- * F-> February
- * d-> 15
- * D-> Mon
- * l-> Monday
- * H-> 02
- * i-> 43
- * s-> 38
- * More mask values in -> http://www.php.net/manual/en/function.date.php

- * - * @return string - */ - public function format(string $mask) : string - { - /** - * - * IMPLEMENTAR ESSE METODO NOVAMENTE PARA SUPORTE DAS TRADUCOES COMENTADAS - * - */ - // require 'Frogg/lang/'.LANGUAGE.'.php'; - - // /* D-># */ $sem = array($lang['Sun'],$lang['Mon'],$lang['Tue'],$lang['Wed'],$lang['Thu'],$lang['Fri'],$lang['Sat']); - // /* l->$ */ $semana = array($lang['Sunday'],$lang['Monday'],$lang['Tuesday'],$lang['Wednesday'],$lang['Thursday'],$lang['Friday'],$lang['Saturday']); - // /* M->% */ $mes = array('',$lang['Jan'],$lang['Feb'],$lang['Mar'],$lang['Apr'],$lang['May'],$lang['Jun'],$lang['Jul'],$lang['Aug'],$lang['Sep'],$lang['Oct'],$lang['Nov'],$lang['Dec']); - // /* F->& */ $meses = array('',$lang['January'],$lang['February'],$lang['March'],$lang['April'],$lang['May'],$lang['June'],$lang['July'],$lang['August'],$lang['September'],$lang['October'],$lang['November'],$lang['December']); - - // $patterns = array('/D/','/l/','/M/','/F/'); - // $replacements = array('#','q','%','}'); - // $mask = preg_replace($patterns, $replacements, $mask); - - $mask = date($mask, $this->time); - // $patterns = array('/#/','/q/','/%/','/}/'); - // $replacements = array($sem[date('w',$this->time)],$semana[date('w',$this->time)],$mes[date('n',$this->time)],$meses[date('n',$this->time)]); - - // return preg_replace($patterns, $replacements, $mask); - return $mask; - } - - /** - * Transforms minutes in seconds - * - * @param int $minutes Quantity of minutes to be transformed into seconds - * - * @return int - */ - public static function secondsFromMinutes(int $minutes) : int - { - return self::MINUTE * $minutes; - } - - /** - * Transforms hours in seconds - * - * @param int $hours Quantity of hours to be transformed into seconds - * - * @return int - */ - public static function secondsFromHours(int $hours) : int - { - return self::HOUR * $hours; - } - - /** - * Transforms days in seconds - * - * @param int $days Quantity of days to be transformed into seconds - * - * @return int - */ - public static function secondsFromDays(int $days) : int - { - return self::DAY * $days; - } -} diff --git a/src/Time/DateInterval.php b/src/Time/DateInterval.php deleted file mode 100644 index 4b4c85b..0000000 --- a/src/Time/DateInterval.php +++ /dev/null @@ -1,78 +0,0 @@ -time = $laterTime - $time; - } else { - $this->time = time() - $time; - } - } - - /** - * @return int Interval in years - */ - public function toYears() : int - { - return floor($this->toDays() / 365); - } - - /** - * @return int Interval in months - */ - public function toMonths() : int - { - return floor(($this->toDays()) / 30); - } - - /** - * @return int Interval in days - */ - public function toDays() : int - { - return floor(($this->toHours()) / 24); - } - - /** - * @return int Interval in hours - */ - public function toHours() : int - { - return floor(($this->toMinutes()) / 60); - } - - /** - * @return int Interval in minutes - */ - public function toMinutes() : int - { - return floor(($this->toSeconds()) / 60); - } - - /** - * @return int Interval in seconds - */ - public function toSeconds() : int - { - return $this->time * 1; - } - -} diff --git a/src/Upload.php b/src/Upload.php deleted file mode 100644 index 648a6b1..0000000 --- a/src/Upload.php +++ /dev/null @@ -1,5270 +0,0 @@ - - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @copyright Colin Verot - * @deprecated Use magroski/bob-ross - */ -class Upload -{ - - /** - * Class version - * - * @access public - * @var string - */ - var $version; - - /** - * Uploaded file name - * - * @access public - * @var string - */ - var $file_src_name; - - /** - * Uploaded file name body (i.e. without extension) - * - * @access public - * @var string - */ - var $file_src_name_body; - - /** - * Uploaded file name extension - * - * @access public - * @var string - */ - var $file_src_name_ext; - - /** - * Uploaded file MIME type - * - * @access public - * @var string - */ - var $file_src_mime; - - /** - * Uploaded file size, in bytes - * - * @access public - * @var double - */ - var $file_src_size; - - /** - * Holds eventual PHP error code from $_FILES - * - * @access public - * @var string - */ - var $file_src_error; - - /** - * Uloaded file name, including server path - * - * @access public - * @var string - */ - var $file_src_pathname; - - /** - * Uloaded file name temporary copy - * - * @access private - * @var string - */ - var $file_src_temp; - - /** - * Destination file name - * - * @access public - * @var string - */ - var $file_dst_path; - - /** - * Destination file name - * - * @access public - * @var string - */ - var $file_dst_name; - - /** - * Destination file name body (i.e. without extension) - * - * @access public - * @var string - */ - var $file_dst_name_body; - - /** - * Destination file extension - * - * @access public - * @var string - */ - var $file_dst_name_ext; - - /** - * Destination file name, including path - * - * @access public - * @var string - */ - var $file_dst_pathname; - - /** - * Source image width - * - * @access public - * @var integer - */ - var $image_src_x; - - /** - * Source image height - * - * @access public - * @var integer - */ - var $image_src_y; - - /** - * Source image color depth - * - * @access public - * @var integer - */ - var $image_src_bits; - - /** - * Number of pixels - * - * @access public - * @var long - */ - var $image_src_pixels; - - /** - * Type of image (png, gif, jpg or bmp) - * - * @access public - * @var string - */ - var $image_src_type; - - /** - * Destination image width - * - * @access public - * @var integer - */ - var $image_dst_x; - - /** - * Destination image height - * - * @access public - * @var integer - */ - var $image_dst_y; - - /** - * Destination image type (png, gif, jpg or bmp) - * - * @access public - * @var integer - */ - var $image_dst_type; - - /** - * Supported image formats - * - * @access private - * @var array - */ - var $image_supported; - - /** - * Flag to determine if the source file is an image - * - * @access public - * @var boolean - */ - var $file_is_image; - - /** - * Flag set after instanciating the class - * - * Indicates if the file has been uploaded properly - * - * @access public - * @var bool - */ - var $uploaded; - - /** - * Flag stopping PHP upload checks - * - * Indicates whether we instanciated the class with a filename, in which case - * we will not check on the validity of the PHP *upload* - * - * This flag is automatically set to true when working on a local file - * - * Warning: for uploads, this flag MUST be set to false for security reason - * - * @access public - * @var bool - */ - var $no_upload_check; - - /** - * Flag set after calling a process - * - * Indicates if the processing, and copy of the resulting file went OK - * - * @access public - * @var bool - */ - var $processed; - - /** - * Holds eventual error message in plain english - * - * @access public - * @var string - */ - var $error; - - /** - * Holds an HTML formatted log - * - * @access public - * @var string - */ - var $log; - - // overiddable processing variables - - /** - * Set this variable to replace the name body (i.e. without extension) - * - * @access public - * @var string - */ - var $file_new_name_body; - - /** - * Set this variable to append a string to the file name body - * - * @access public - * @var string - */ - var $file_name_body_add; - - /** - * Set this variable to prepend a string to the file name body - * - * @access public - * @var string - */ - var $file_name_body_pre; - - /** - * Set this variable to change the file extension - * - * @access public - * @var string - */ - var $file_new_name_ext; - - /** - * Set this variable to format the filename (spaces changed to _) - * - * @access public - * @var boolean - */ - var $file_safe_name; - - /** - * Forces an extension if the source file doesn't have one - * - * If the file is an image, then the correct extension will be added - * Otherwise, a .txt extension will be chosen - * - * @access public - * @var boolean - */ - var $file_force_extension; - - /** - * Set this variable to false if you don't want to check the MIME against the allowed list - * - * This variable is set to true by default for security reason - * - * @access public - * @var boolean - */ - var $mime_check; - - /** - * Set this variable to false in the init() function if you don't want to check the MIME - * with Fileinfo PECL extension. On some systems, Fileinfo is known to be buggy, and you - * may want to deactivate it in the class code directly. - * - * You can also set it with the path of the magic database file. - * If set to true, the class will try to read the MAGIC environment variable - * and if it is empty, will default to the system's default - * If set to an empty string, it will call finfo_open without the path argument - * - * This variable is set to true by default for security reason - * - * @access public - * @var boolean - */ - var $mime_fileinfo; - - /** - * Set this variable to false in the init() function if you don't want to check the MIME - * with UNIX file() command - * - * This variable is set to true by default for security reason - * - * @access public - * @var boolean - */ - var $mime_file; - - /** - * Set this variable to false in the init() function if you don't want to check the MIME - * with the magic.mime file - * - * The function mime_content_type() will be deprecated, - * and this variable will be set to false in a future release - * - * This variable is set to true by default for security reason - * - * @access public - * @var boolean - */ - var $mime_magic; - - /** - * Set this variable to false in the init() function if you don't want to check the MIME - * with getimagesize() - * - * The class tries to get a MIME type from getimagesize() - * If no MIME is returned, it tries to guess the MIME type from the file type - * - * This variable is set to true by default for security reason - * - * @access public - * @var boolean - */ - var $mime_getimagesize; - - /** - * Set this variable to false if you don't want to turn dangerous scripts into simple text files - * - * @access public - * @var boolean - */ - var $no_script; - - /** - * Set this variable to true to allow automatic renaming of the file - * if the file already exists - * - * Default value is true - * - * For instance, on uploading foo.ext,
- * if foo.ext already exists, upload will be renamed foo_1.ext
- * and if foo_1.ext already exists, upload will be renamed foo_2.ext
- * - * Note that this option doesn't have any effect if {@link file_overwrite} is true - * - * @access public - * @var bool - */ - var $file_auto_rename; - - /** - * Set this variable to true to allow automatic creation of the destination - * directory if it is missing (works recursively) - * - * Default value is true - * - * @access public - * @var bool - */ - var $dir_auto_create; - - /** - * Set this variable to true to allow automatic chmod of the destination - * directory if it is not writeable - * - * Default value is true - * - * @access public - * @var bool - */ - var $dir_auto_chmod; - - /** - * Set this variable to the default chmod you want the class to use - * when creating directories, or attempting to write in a directory - * - * Default value is 0777 (without quotes) - * - * @access public - * @var bool - */ - var $dir_chmod; - - /** - * Set this variable tu true to allow overwriting of an existing file - * - * Default value is false, so no files will be overwritten - * - * @access public - * @var bool - */ - var $file_overwrite; - - /** - * Set this variable to change the maximum size in bytes for an uploaded file - * - * Default value is the value upload_max_filesize from php.ini - * - * Value in bytes (integer) or shorthand byte values (string) is allowed. - * The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes) - * - * @access public - * @var double - */ - var $file_max_size; - - /** - * Set this variable to true to resize the file if it is an image - * - * You will probably want to set {@link image_x} and {@link image_y}, and maybe one of the ratio variables - * - * Default value is false (no resizing) - * - * @access public - * @var bool - */ - var $image_resize; - - /** - * Set this variable to convert the file if it is an image - * - * Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp' - * - * Default value is '' (no conversion)
- * If {@link resize} is true, {@link convert} will be set to the source file extension - * - * @access public - * @var string - */ - var $image_convert; - - /** - * Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels - * - * Default value is 150 - * - * @access public - * @var integer - */ - var $image_x; - - /** - * Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels - * - * Default value is 150 - * - * @access public - * @var integer - */ - var $image_y; - - /** - * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} - * - * Default value is false - * - * @access public - * @var bool - */ - var $image_ratio; - - /** - * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} - * - * The image will be resized as to fill the whole space, and excedent will be cropped - * - * Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) - * If set as a string, it determines which side of the image is kept while cropping. - * By default, the part of the image kept is in the center, i.e. it crops equally on both sides - * - * Default value is false - * - * @access public - * @var mixed - */ - var $image_ratio_crop; - - /** - * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} - * - * The image will be resized to fit entirely in the space, and the rest will be colored. - * The default color is white, but can be set with {@link image_default_color} - * - * Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) - * If set as a string, it determines in which side of the space the image is displayed. - * By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides - * - * Default value is false - * - * @access public - * @var mixed - */ - var $image_ratio_fill; - - /** - * Set this variable to a number of pixels so that {@link image_x} and {@link image_y} are the best match possible - * - * The image will be resized to have approximatively the number of pixels - * The aspect ratio wil be conserved - * - * Default value is false - * - * @access public - * @var mixed - */ - var $image_ratio_pixels; - - /** - * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}, - * but only if original image is bigger - * - * Default value is false - * - * @access public - * @var bool - */ - var $image_ratio_no_zoom_in; - - /** - * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}, - * but only if original image is smaller - * - * Default value is false - * - * @access public - * @var bool - */ - var $image_ratio_no_zoom_out; - - /** - * Set this variable to calculate {@link image_x} automatically , using {@link image_y} and conserving ratio - * - * Default value is false - * - * @access public - * @var bool - */ - var $image_ratio_x; - - /** - * Set this variable to calculate {@link image_y} automatically , using {@link image_x} and conserving ratio - * - * Default value is false - * - * @access public - * @var bool - */ - var $image_ratio_y; - - /** - * Set this variable to set a maximum image width, above which the upload will be invalid - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_max_width; - - /** - * Set this variable to set a maximum image height, above which the upload will be invalid - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_max_height; - - /** - * Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid - * - * Default value is null - * - * @access public - * @var long - */ - var $image_max_pixels; - - /** - * Set this variable to set a maximum image aspect ratio, above which the upload will be invalid - * - * Note that ratio = width / height - * - * Default value is null - * - * @access public - * @var float - */ - var $image_max_ratio; - - /** - * Set this variable to set a minimum image width, below which the upload will be invalid - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_min_width; - - /** - * Set this variable to set a minimum image height, below which the upload will be invalid - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_min_height; - - /** - * Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid - * - * Default value is null - * - * @access public - * @var long - */ - var $image_min_pixels; - - /** - * Set this variable to set a minimum image aspect ratio, below which the upload will be invalid - * - * Note that ratio = width / height - * - * Default value is null - * - * @access public - * @var float - */ - var $image_min_ratio; - - /** - * Compression level for PNG images - * - * Between 1 (fast but large files) and 9 (slow but smaller files) - * - * Default value is null (Zlib default) - * - * @access public - * @var integer - */ - var $png_compression; - - /** - * Quality of JPEG created/converted destination image - * - * Default value is 85 - * - * @access public - * @var integer - */ - var $jpeg_quality; - - /** - * Determines the quality of the JPG image to fit a desired file size - * - * The JPG quality will be set between 1 and 100% - * The calculations are approximations. - * - * Value in bytes (integer) or shorthand byte values (string) is allowed. - * The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes) - * - * Default value is null (no calculations) - * - * @access public - * @var integer - */ - var $jpeg_size; - - /** - * Turns the interlace bit on - * - * This is actually used only for JPEG images, and defaults to false - * - * @access public - * @var boolean - */ - var $image_interlace; - - /** - * Preserve transparency when resizing or converting an image (deprecated) - * - * Default value is automatically set to true for transparent GIFs - * This setting is now deprecated - * - * @access public - * @var integer - */ - var $preserve_transparency; - - /** - * Flag set to true when the image is transparent - * - * This is actually used only for transparent GIFs - * - * @access public - * @var boolean - */ - var $image_is_transparent; - - /** - * Transparent color in a palette - * - * This is actually used only for transparent GIFs - * - * @access public - * @var boolean - */ - var $image_transparent_color; - - /** - * Background color, used to paint transparent areas with - * - * If set, it will forcibly remove transparency by painting transparent areas with the color - * This setting will fill in all transparent areas in PNG and GIF, as opposed to {@link image_default_color} - * which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs - * This setting overrides {@link image_default_color} - * - * Default value is null - * - * @access public - * @var string - */ - var $image_background_color; - - /** - * Default color for non alpha-transparent images - * - * This setting is to be used to define a background color for semi transparent areas - * of an alpha transparent when the output format doesn't support alpha transparency - * This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features - * if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas - * If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas - * - * The default color white - * - * @access public - * @var boolean - */ - var $image_default_color; - - /** - * Flag set to true when the image is not true color - * - * @access public - * @var boolean - */ - var $image_is_palette; - - /** - * Corrects the image brightness - * - * Value can range between -127 and 127 - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_brightness; - - /** - * Corrects the image contrast - * - * Value can range between -127 and 127 - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_contrast; - - /** - * Changes the image opacity - * - * Value can range between 0 and 100 - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_opacity; - - /** - * Applies threshold filter - * - * Value can range between -127 and 127 - * - * Default value is null - * - * @access public - * @var integer - */ - var $image_threshold; - - /** - * Applies a tint on the image - * - * Value is an hexadecimal color, such as #FFFFFF - * - * Default value is null - * - * @access public - * @var string; - */ - var $image_tint_color; - - /** - * Applies a colored overlay on the image - * - * Value is an hexadecimal color, such as #FFFFFF - * - * To use with {@link image_overlay_opacity} - * - * Default value is null - * - * @access public - * @var string; - */ - var $image_overlay_color; - - /** - * Sets the opacity for the colored overlay - * - * Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) - * - * Unless used with {@link image_overlay_color}, this setting has no effect - * - * Default value is 50 - * - * @access public - * @var integer - */ - var $image_overlay_opacity; - - /** - * Soon to be deprecated old form of {@link image_overlay_opacity} - * - * @access public - * @var integer - */ - var $image_overlay_percent; - - /** - * Inverts the color of an image - * - * Default value is FALSE - * - * @access public - * @var boolean; - */ - var $image_negative; - - /** - * Turns the image into greyscale - * - * Default value is FALSE - * - * @access public - * @var boolean; - */ - var $image_greyscale; - - /** - * Pixelate an image - * - * Value is integer, represents the block size - * - * Default value is null - * - * @access public - * @var integer; - */ - var $image_pixelate; - - /** - * Applies an unsharp mask, with alpha transparency support - * - * Beware that this unsharp mask is quite resource-intensive - * - * Default value is FALSE - * - * @access public - * @var boolean; - */ - var $image_unsharp; - - /** - * Sets the unsharp mask amount - * - * Value is an integer between 0 and 500, typically between 50 and 200 - * - * Unless used with {@link image_unsharp}, this setting has no effect - * - * Default value is 80 - * - * @access public - * @var integer - */ - var $image_unsharp_amount; - - /** - * Sets the unsharp mask radius - * - * Value is an integer between 0 and 50, typically between 0.5 and 1 - * It is not recommended to change it, the default works best - * - * Unless used with {@link image_unsharp}, this setting has no effect - * - * From PHP 5.1, imageconvolution is used, and this setting has no effect - * - * Default value is 0.5 - * - * @access public - * @var integer - */ - var $image_unsharp_radius; - - /** - * Sets the unsharp mask threshold - * - * Value is an integer between 0 and 255, typically between 0 and 5 - * - * Unless used with {@link image_unsharp}, this setting has no effect - * - * Default value is 1 - * - * @access public - * @var integer - */ - var $image_unsharp_threshold; - - /** - * Adds a text label on the image - * - * Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n" - * - * If set, this setting allow the use of all other settings starting with image_text_ - * - * Replacement tokens can be used in the string: - *
-     * gd_version    src_name       src_name_body src_name_ext
-     * src_pathname  src_mime       src_x         src_y
-     * src_type      src_bits       src_pixels
-     * src_size      src_size_kb    src_size_mb   src_size_human
-     * dst_path      dst_name_body  dst_pathname
-     * dst_name      dst_name_ext   dst_x         dst_y
-     * date          time           host          server        ip
-     * 
- * The tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture - * - * Default value is null - * - * @access public - * @var string; - */ - var $image_text; - - /** - * Sets the text direction for the text label - * - * Value is either 'h' or 'v', as in horizontal and vertical - * - * Default value is h (horizontal) - * - * @access public - * @var string; - */ - var $image_text_direction; - - /** - * Sets the text color for the text label - * - * Value is an hexadecimal color, such as #FFFFFF - * - * Default value is #FFFFFF (white) - * - * @access public - * @var string; - */ - var $image_text_color; - - /** - * Sets the text opacity in the text label - * - * Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) - * - * Default value is 100 - * - * @access public - * @var integer - */ - var $image_text_opacity; - - /** - * Soon to be deprecated old form of {@link image_text_opacity} - * - * @access public - * @var integer - */ - var $image_text_percent; - - /** - * Sets the text background color for the text label - * - * Value is an hexadecimal color, such as #FFFFFF - * - * Default value is null (no background) - * - * @access public - * @var string; - */ - var $image_text_background; - - /** - * Sets the text background opacity in the text label - * - * Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) - * - * Default value is 100 - * - * @access public - * @var integer - */ - var $image_text_background_opacity; - - /** - * Soon to be deprecated old form of {@link image_text_background_opacity} - * - * @access public - * @var integer - */ - var $image_text_background_percent; - - /** - * Sets the text font in the text label - * - * Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest - * Value can also be a string, which represents the path to a GDF font. The font will be loaded into GD, and used - * as a built-in font. - * - * Default value is 5 - * - * @access public - * @var mixed; - */ - var $image_text_font; - - /** - * Sets the text label position within the image - * - * Value is one or two out of 'TBLR' (top, bottom, left, right) - * - * The positions are as following: - *
-     *                        TL  T  TR
-     *                        L       R
-     *                        BL  B  BR
-     * 
- * - * Default value is null (centered, horizontal and vertical) - * - * Note that is {@link image_text_x} and {@link image_text_y} are used, this setting has no effect - * - * @access public - * @var string; - */ - var $image_text_position; - - /** - * Sets the text label absolute X position within the image - * - * Value is in pixels, representing the distance between the left of the image and the label - * If a negative value is used, it will represent the distance between the right of the image and the label - * - * Default value is null (so {@link image_text_position} is used) - * - * @access public - * @var integer - */ - var $image_text_x; - - /** - * Sets the text label absolute Y position within the image - * - * Value is in pixels, representing the distance between the top of the image and the label - * If a negative value is used, it will represent the distance between the bottom of the image and the label - * - * Default value is null (so {@link image_text_position} is used) - * - * @access public - * @var integer - */ - var $image_text_y; - - /** - * Sets the text label padding - * - * Value is in pixels, representing the distance between the text and the label background border - * - * Default value is 0 - * - * This setting can be overriden by {@link image_text_padding_x} and {@link image_text_padding_y} - * - * @access public - * @var integer - */ - var $image_text_padding; - - /** - * Sets the text label horizontal padding - * - * Value is in pixels, representing the distance between the text and the left and right label background borders - * - * Default value is null - * - * If set, this setting overrides the horizontal part of {@link image_text_padding} - * - * @access public - * @var integer - */ - var $image_text_padding_x; - - /** - * Sets the text label vertical padding - * - * Value is in pixels, representing the distance between the text and the top and bottom label background borders - * - * Default value is null - * - * If set, his setting overrides the vertical part of {@link image_text_padding} - * - * @access public - * @var integer - */ - var $image_text_padding_y; - - /** - * Sets the text alignment - * - * Value is a string, which can be either 'L', 'C' or 'R' - * - * Default value is 'C' - * - * This setting is relevant only if the text has several lines. - * - * @access public - * @var string; - */ - var $image_text_alignment; - - /** - * Sets the text line spacing - * - * Value is an integer, in pixels - * - * Default value is 0 - * - * This setting is relevant only if the text has several lines. - * - * @access public - * @var integer - */ - var $image_text_line_spacing; - - /** - * Sets the height of the reflection - * - * Value is an integer in pixels, or a string which format can be in pixels or percentage. - * For instance, values can be : 40, '40', '40px' or '40%' - * - * Default value is null, no reflection - * - * @access public - * @var mixed; - */ - var $image_reflection_height; - - /** - * Sets the space between the source image and its relection - * - * Value is an integer in pixels, which can be negative - * - * Default value is 2 - * - * This setting is relevant only if {@link image_reflection_height} is set - * - * @access public - * @var integer - */ - var $image_reflection_space; - - /** - * Sets the color of the reflection background (deprecated) - * - * Value is an hexadecimal color, such as #FFFFFF - * - * Default value is #FFFFFF - * - * This setting is relevant only if {@link image_reflection_height} is set - * - * This setting is now deprecated in favor of {@link image_default_color} - * - * @access public - * @var string; - */ - var $image_reflection_color; - - /** - * Sets the initial opacity of the reflection - * - * Value is an integer between 0 (no opacity) and 100 (full opacity). - * The reflection will start from {@link image_reflection_opacity} and end up at 0 - * - * Default value is 60 - * - * This setting is relevant only if {@link image_reflection_height} is set - * - * @access public - * @var integer - */ - var $image_reflection_opacity; - - /** - * Automatically rotates the image according to EXIF data (JPEG only) - * - * Default value is true - * - * @access public - * @var boolean; - */ - var $image_auto_rotate; - - /** - * Flips the image vertically or horizontally - * - * Value is either 'h' or 'v', as in horizontal and vertical - * - * Default value is null (no flip) - * - * @access public - * @var string; - */ - var $image_flip; - - /** - * Rotates the image by increments of 45 degrees - * - * Value is either 90, 180 or 270 - * - * Default value is null (no rotation) - * - * @access public - * @var string; - */ - var $image_rotate; - - /** - * Crops an image - * - * Values are four dimensions, or two, or one (CSS style) - * They represent the amount cropped top, right, bottom and left. - * These values can either be in an array, or a space separated string. - * Each value can be in pixels (with or without 'px'), or percentage (of the source image) - * - * For instance, are valid: - *
-     * $foo->image_crop = 20                  OR array(20);
-     * $foo->image_crop = '20px'              OR array('20px');
-     * $foo->image_crop = '20 40'             OR array('20', 40);
-     * $foo->image_crop = '-20 25%'           OR array(-20, '25%');
-     * $foo->image_crop = '20px 25%'          OR array('20px', '25%');
-     * $foo->image_crop = '20% 25%'           OR array('20%', '25%');
-     * $foo->image_crop = '20% 25% 10% 30%'   OR array('20%', '25%', '10%', '30%');
-     * $foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px');
-     * $foo->image_crop = '20 25% 40px 10%'   OR array(20, '25%', '40px', '10%');
-     * 
- * - * If a value is negative, the image will be expanded, and the extra parts will be filled with black - * - * Default value is null (no cropping) - * - * @access public - * @var string OR array; - */ - var $image_crop; - - /** - * Crops an image, before an eventual resizing - * - * See {@link image_crop} for valid formats - * - * Default value is null (no cropping) - * - * @access public - * @var string OR array; - */ - var $image_precrop; - - /** - * Adds a bevel border on the image - * - * Value is a positive integer, representing the thickness of the bevel - * - * If the bevel colors are the same as the background, it makes a fade out effect - * - * Default value is null (no bevel) - * - * @access public - * @var integer - */ - var $image_bevel; - - /** - * Top and left bevel color - * - * Value is a color, in hexadecimal format - * This setting is used only if {@link image_bevel} is set - * - * Default value is #FFFFFF - * - * @access public - * @var string; - */ - var $image_bevel_color1; - - /** - * Right and bottom bevel color - * - * Value is a color, in hexadecimal format - * This setting is used only if {@link image_bevel} is set - * - * Default value is #000000 - * - * @access public - * @var string; - */ - var $image_bevel_color2; - - /** - * Adds a single-color border on the outer of the image - * - * Values are four dimensions, or two, or one (CSS style) - * They represent the border thickness top, right, bottom and left. - * These values can either be in an array, or a space separated string. - * Each value can be in pixels (with or without 'px'), or percentage (of the source image) - * - * See {@link image_crop} for valid formats - * - * If a value is negative, the image will be cropped. - * Note that the dimensions of the picture will be increased by the borders' thickness - * - * Default value is null (no border) - * - * @access public - * @var integer - */ - var $image_border; - - /** - * Border color - * - * Value is a color, in hexadecimal format. - * This setting is used only if {@link image_border} is set - * - * Default value is #FFFFFF - * - * @access public - * @var string; - */ - var $image_border_color; - - /** - * Sets the opacity for the borders - * - * Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) - * - * Unless used with {@link image_border}, this setting has no effect - * - * Default value is 100 - * - * @access public - * @var integer - */ - var $image_border_opacity; - - /** - * Adds a fading-to-transparent border on the image - * - * Values are four dimensions, or two, or one (CSS style) - * They represent the border thickness top, right, bottom and left. - * These values can either be in an array, or a space separated string. - * Each value can be in pixels (with or without 'px'), or percentage (of the source image) - * - * See {@link image_crop} for valid formats - * - * Note that the dimensions of the picture will not be increased by the borders' thickness - * - * Default value is null (no border) - * - * @access public - * @var integer - */ - var $image_border_transparent; - - /** - * Adds a multi-color frame on the outer of the image - * - * Value is an integer. Two values are possible for now: - * 1 for flat border, meaning that the frame is mirrored horizontally and vertically - * 2 for crossed border, meaning that the frame will be inversed, as in a bevel effect - * - * The frame will be composed of colored lines set in {@link image_frame_colors} - * - * Note that the dimensions of the picture will be increased by the borders' thickness - * - * Default value is null (no frame) - * - * @access public - * @var integer - */ - var $image_frame; - - /** - * Sets the colors used to draw a frame - * - * Values is a list of n colors in hexadecimal format. - * These values can either be in an array, or a space separated string. - * - * The colors are listed in the following order: from the outset of the image to its center - * - * For instance, are valid: - *
-     * $foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
-     * $foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000');
-     * 
- * - * This setting is used only if {@link image_frame} is set - * - * Default value is '#FFFFFF #999999 #666666 #000000' - * - * @access public - * @var string OR array; - */ - var $image_frame_colors; - - /** - * Sets the opacity for the frame - * - * Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) - * - * Unless used with {@link image_frame}, this setting has no effect - * - * Default value is 100 - * - * @access public - * @var integer - */ - var $image_frame_opacity; - - /** - * Adds a watermark on the image - * - * Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha. - * - * If set, this setting allow the use of all other settings starting with image_watermark_ - * - * Default value is null - * - * @access public - * @var string; - */ - var $image_watermark; - - /** - * Sets the watermarkposition within the image - * - * Value is one or two out of 'TBLR' (top, bottom, left, right) - * - * The positions are as following: TL T TR - * L R - * BL B BR - * - * Default value is null (centered, horizontal and vertical) - * - * Note that is {@link image_watermark_x} and {@link image_watermark_y} are used, this setting has no effect - * - * @access public - * @var string; - */ - var $image_watermark_position; - - /** - * Sets the watermark absolute X position within the image - * - * Value is in pixels, representing the distance between the top of the image and the watermark - * If a negative value is used, it will represent the distance between the bottom of the image and the watermark - * - * Default value is null (so {@link image_watermark_position} is used) - * - * @access public - * @var integer - */ - var $image_watermark_x; - - /** - * Sets the twatermark absolute Y position within the image - * - * Value is in pixels, representing the distance between the left of the image and the watermark - * If a negative value is used, it will represent the distance between the right of the image and the watermark - * - * Default value is null (so {@link image_watermark_position} is used) - * - * @access public - * @var integer - */ - var $image_watermark_y; - - /** - * Prevents the watermark to be resized up if it is smaller than the image - * - * If the watermark if smaller than the destination image, taking in account the desired watermark position - * then it will be resized up to fill in the image (minus the {@link image_watermark_x} or {@link - * image_watermark_y} values) - * - * If you don't want your watermark to be resized in any way, then - * set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to true - * If you want your watermark to be resized up or doan to fill in the image better, then - * set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to false - * - * Default value is true (so the watermark will not be resized up, which is the behaviour most people expect) - * - * @access public - * @var integer - */ - var $image_watermark_no_zoom_in; - - /** - * Prevents the watermark to be resized down if it is bigger than the image - * - * If the watermark if bigger than the destination image, taking in account the desired watermark position - * then it will be resized down to fit in the image (minus the {@link image_watermark_x} or {@link - * image_watermark_y} values) - * - * If you don't want your watermark to be resized in any way, then - * set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to true - * If you want your watermark to be resized up or doan to fill in the image better, then - * set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to false - * - * Default value is false (so the watermark may be shrinked to fit in the image) - * - * @access public - * @var integer - */ - var $image_watermark_no_zoom_out; - - /** - * List of MIME types per extension - * - * @access private - * @var array - */ - var $mime_types; - - /** - * Allowed MIME types - * - * Default is a selection of safe mime-types, but you might want to change it - * - * Simple wildcards are allowed, such as image/* or application/* - * If there is only one MIME type allowed, then it can be a string instead of an array - * - * @access public - * @var array OR string - */ - var $allowed; - - /** - * Forbidden MIME types - * - * Default is a selection of safe mime-types, but you might want to change it - * To only check for forbidden MIME types, and allow everything else, set {@link allowed} to array('* / *') without - * the spaces - * - * Simple wildcards are allowed, such as image/* or application/* - * If there is only one MIME type forbidden, then it can be a string instead of an array - * - * @access public - * @var array OR string - */ - var $forbidden; - - /** - * Array of translated error messages - * - * By default, the language is english (en_GB) - * Translations can be in separate files, in a lang/ subdirectory - * - * @access public - * @var array - */ - var $translation; - - /** - * Language selected for the translations - * - * By default, the language is english ("en_GB") - * - * @access public - * @var array - */ - var $lang; - - /** - * Init or re-init all the processing variables to their default values - * - * This function is called in the constructor, and after each call of {@link process} - * - * @access private - */ - function init() - { - // overiddable variables - $this->file_new_name_body = null; // replace the name body - $this->file_name_body_add = null; // append to the name body - $this->file_name_body_pre = null; // prepend to the name body - $this->file_new_name_ext = null; // replace the file extension - $this->file_safe_name = true; // format safely the filename - $this->file_force_extension = true; // forces extension if there isn't one - $this->file_overwrite = false; // allows overwritting if the file already exists - $this->file_auto_rename = true; // auto-rename if the file already exists - $this->dir_auto_create = true; // auto-creates directory if missing - $this->dir_auto_chmod = true; // auto-chmod directory if not writeable - $this->dir_chmod = 0777; // default chmod to use - - $this->no_script = true; // turns scripts into test files - $this->mime_check = true; // checks the mime type against the allowed list - - // these are the different MIME detection methods. if one of these method doesn't work on your - // system, you can deactivate it here; just set it to false - $this->mime_fileinfo = true; // MIME detection with Fileinfo PECL extension - $this->mime_file = true; // MIME detection with UNIX file() command - $this->mime_magic = true; // MIME detection with mime_magic (mime_content_type()) - $this->mime_getimagesize = true; // MIME detection with getimagesize() - - // get the default max size from php.ini - $this->file_max_size_raw = trim(ini_get('upload_max_filesize')); - $this->file_max_size = $this->getsize($this->file_max_size_raw); - - $this->image_resize = false; // resize the image - $this->image_convert = ''; // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp' - - $this->image_x = 150; - $this->image_y = 150; - $this->image_ratio = false; // keeps aspect ratio with x and y dimensions - $this->image_ratio_crop = false; // keeps aspect ratio with x and y dimensions, filling the space - $this->image_ratio_fill = false; // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest - $this->image_ratio_pixels = false; // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels - $this->image_ratio_no_zoom_in = false; - $this->image_ratio_no_zoom_out = false; - $this->image_ratio_x = false; // calculate the $image_x if true - $this->image_ratio_y = false; // calculate the $image_y if true - $this->png_compression = null; - $this->jpeg_quality = 85; - $this->jpeg_size = null; - $this->image_interlace = false; - $this->preserve_transparency = false; - $this->image_is_transparent = false; - $this->image_transparent_color = null; - $this->image_background_color = null; - $this->image_default_color = '#ffffff'; - $this->image_is_palette = false; - - $this->image_max_width = null; - $this->image_max_height = null; - $this->image_max_pixels = null; - $this->image_max_ratio = null; - $this->image_min_width = null; - $this->image_min_height = null; - $this->image_min_pixels = null; - $this->image_min_ratio = null; - - $this->image_brightness = null; - $this->image_contrast = null; - $this->image_opacity = null; - $this->image_threshold = null; - $this->image_tint_color = null; - $this->image_overlay_color = null; - $this->image_overlay_opacity = null; - $this->image_overlay_percent = null; - $this->image_negative = false; - $this->image_greyscale = false; - $this->image_pixelate = null; - $this->image_unsharp = false; - $this->image_unsharp_amount = 80; - $this->image_unsharp_radius = 0.5; - $this->image_unsharp_threshold = 1; - - $this->image_text = null; - $this->image_text_direction = null; - $this->image_text_color = '#FFFFFF'; - $this->image_text_opacity = 100; - $this->image_text_percent = 100; - $this->image_text_background = null; - $this->image_text_background_opacity = 100; - $this->image_text_background_percent = 100; - $this->image_text_font = 5; - $this->image_text_x = null; - $this->image_text_y = null; - $this->image_text_position = null; - $this->image_text_padding = 0; - $this->image_text_padding_x = null; - $this->image_text_padding_y = null; - $this->image_text_alignment = 'C'; - $this->image_text_line_spacing = 0; - - $this->image_reflection_height = null; - $this->image_reflection_space = 2; - $this->image_reflection_color = '#ffffff'; - $this->image_reflection_opacity = 60; - - $this->image_watermark = null; - $this->image_watermark_x = null; - $this->image_watermark_y = null; - $this->image_watermark_position = null; - $this->image_watermark_no_zoom_in = true; - $this->image_watermark_no_zoom_out = false; - - $this->image_flip = null; - $this->image_auto_rotate = true; - $this->image_rotate = null; - $this->image_crop = null; - $this->image_precrop = null; - - $this->image_bevel = null; - $this->image_bevel_color1 = '#FFFFFF'; - $this->image_bevel_color2 = '#000000'; - $this->image_border = null; - $this->image_border_color = '#FFFFFF'; - $this->image_border_opacity = 100; - $this->image_border_transparent = null; - $this->image_frame = null; - $this->image_frame_colors = '#FFFFFF #999999 #666666 #000000'; - $this->image_frame_opacity = 100; - - $this->forbidden = []; - $this->allowed = [ - 'application/arj', - 'application/excel', - 'application/gnutar', - 'application/mspowerpoint', - 'application/msword', - 'application/octet-stream', - 'application/onenote', - 'application/pdf', - 'application/plain', - 'application/postscript', - 'application/powerpoint', - 'application/rar', - 'application/rtf', - 'application/vnd.ms-excel', - 'application/vnd.ms-excel.addin.macroEnabled.12', - 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', - 'application/vnd.ms-excel.sheet.macroEnabled.12', - 'application/vnd.ms-excel.template.macroEnabled.12', - 'application/vnd.ms-office', - 'application/vnd.ms-officetheme', - 'application/vnd.ms-powerpoint', - 'application/vnd.ms-powerpoint.addin.macroEnabled.12', - 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', - 'application/vnd.ms-powerpoint.slide.macroEnabled.12', - 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', - 'application/vnd.ms-powerpoint.template.macroEnabled.12', - 'application/vnd.ms-word', - 'application/vnd.ms-word.document.macroEnabled.12', - 'application/vnd.ms-word.template.macroEnabled.12', - 'application/vnd.oasis.opendocument.chart', - 'application/vnd.oasis.opendocument.database', - 'application/vnd.oasis.opendocument.formula', - 'application/vnd.oasis.opendocument.graphics', - 'application/vnd.oasis.opendocument.graphics-template', - 'application/vnd.oasis.opendocument.image', - 'application/vnd.oasis.opendocument.presentation', - 'application/vnd.oasis.opendocument.presentation-template', - 'application/vnd.oasis.opendocument.spreadsheet', - 'application/vnd.oasis.opendocument.spreadsheet-template', - 'application/vnd.oasis.opendocument.text', - 'application/vnd.oasis.opendocument.text-master', - 'application/vnd.oasis.opendocument.text-template', - 'application/vnd.oasis.opendocument.text-web', - 'application/vnd.openofficeorg.extension', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.slide', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', - 'application/vnd.openxmlformats-officedocument.presentationml.template', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', - 'application/vocaltec-media-file', - 'application/wordperfect', - 'application/x-bittorrent', - 'application/x-bzip', - 'application/x-bzip2', - 'application/x-compressed', - 'application/x-excel', - 'application/x-gzip', - 'application/x-latex', - 'application/x-midi', - 'application/xml', - 'application/x-msexcel', - 'application/x-rar', - 'application/x-rar-compressed', - 'application/x-rtf', - 'application/x-shockwave-flash', - 'application/x-sit', - 'application/x-stuffit', - 'application/x-troff-msvideo', - 'application/x-zip', - 'application/x-zip-compressed', - 'application/zip', - 'audio/*', - 'image/*', - 'multipart/x-gzip', - 'multipart/x-zip', - 'text/plain', - 'text/rtf', - 'text/richtext', - 'text/xml', - 'video/*', - 'text/csv', - ]; - - $this->mime_types = [ - 'jpg' => 'image/jpeg', - 'jpeg' => 'image/jpeg', - 'jpe' => 'image/jpeg', - 'gif' => 'image/gif', - 'png' => 'image/png', - 'bmp' => 'image/bmp', - 'flv' => 'video/x-flv', - 'js' => 'application/x-javascript', - 'json' => 'application/json', - 'tiff' => 'image/tiff', - 'css' => 'text/css', - 'xml' => 'application/xml', - 'doc' => 'application/msword', - 'docx' => 'application/msword', - 'xls' => 'application/vnd.ms-excel', - 'xlt' => 'application/vnd.ms-excel', - 'xlm' => 'application/vnd.ms-excel', - 'xld' => 'application/vnd.ms-excel', - 'xla' => 'application/vnd.ms-excel', - 'xlc' => 'application/vnd.ms-excel', - 'xlw' => 'application/vnd.ms-excel', - 'xll' => 'application/vnd.ms-excel', - 'ppt' => 'application/vnd.ms-powerpoint', - 'pps' => 'application/vnd.ms-powerpoint', - 'rtf' => 'application/rtf', - 'pdf' => 'application/pdf', - 'html' => 'text/html', - 'htm' => 'text/html', - 'php' => 'text/html', - 'txt' => 'text/plain', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'mpe' => 'video/mpeg', - 'mp3' => 'audio/mpeg3', - 'wav' => 'audio/wav', - 'aiff' => 'audio/aiff', - 'aif' => 'audio/aiff', - 'avi' => 'video/msvideo', - 'wmv' => 'video/x-ms-wmv', - 'mov' => 'video/quicktime', - 'zip' => 'application/zip', - 'tar' => 'application/x-tar', - 'swf' => 'application/x-shockwave-flash', - 'odt' => 'application/vnd.oasis.opendocument.text', - 'ott' => 'application/vnd.oasis.opendocument.text-template', - 'oth' => 'application/vnd.oasis.opendocument.text-web', - 'odm' => 'application/vnd.oasis.opendocument.text-master', - 'odg' => 'application/vnd.oasis.opendocument.graphics', - 'otg' => 'application/vnd.oasis.opendocument.graphics-template', - 'odp' => 'application/vnd.oasis.opendocument.presentation', - 'otp' => 'application/vnd.oasis.opendocument.presentation-template', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', - 'odc' => 'application/vnd.oasis.opendocument.chart', - 'odf' => 'application/vnd.oasis.opendocument.formula', - 'odb' => 'application/vnd.oasis.opendocument.database', - 'odi' => 'application/vnd.oasis.opendocument.image', - 'oxt' => 'application/vnd.openofficeorg.extension', - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', - 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', - 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', - 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', - 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', - 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', - 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', - 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', - 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', - 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', - 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', - 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', - 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', - 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', - 'thmx' => 'application/vnd.ms-officetheme', - 'onetoc' => 'application/onenote', - 'onetoc2' => 'application/onenote', - 'onetmp' => 'application/onenote', - 'onepkg' => 'application/onenote', - 'csv' => 'text/csv', - ]; - } - - /** - * Constructor, for PHP5+ - * - * @param $file - * @param string $lang - */ - function __construct($file, $lang = 'en_GB') - { - $this->upload($file, $lang); - } - - /** - * Constructor, for PHP4. Checks if the file has been uploaded - * - * The constructor takes $_FILES['form_field'] array as argument - * where form_field is the form field name - * - * The constructor will check if the file has been uploaded in its temporary location, and - * accordingly will set {@link uploaded} (and {@link error} is an error occurred) - * - * If the file has been uploaded, the constructor will populate all the variables holding the upload - * information (none of the processing class variables are used here). - * You can have access to information about the file (name, size, MIME type...). - * - * - * Alternatively, you can set the first argument to be a local filename (string) - * This allows processing of a local file, as if the file was uploaded - * - * The optional second argument allows you to set the language for the error messages - * - * @access private - * - * @param array $file $_FILES['form_field'] - * or string $file Local filename - * @param string $lang Optional language code - */ - function upload($file, $lang = 'en_GB') - { - $this->version = '0.33'; - - $this->file_src_name = ''; - $this->file_src_name_body = ''; - $this->file_src_name_ext = ''; - $this->file_src_mime = ''; - $this->file_src_size = ''; - $this->file_src_error = ''; - $this->file_src_pathname = ''; - $this->file_src_temp = ''; - - $this->file_dst_path = ''; - $this->file_dst_name = ''; - $this->file_dst_name_body = ''; - $this->file_dst_name_ext = ''; - $this->file_dst_pathname = ''; - - $this->image_src_x = null; - $this->image_src_y = null; - $this->image_src_bits = null; - $this->image_src_type = null; - $this->image_src_pixels = null; - $this->image_dst_x = 0; - $this->image_dst_y = 0; - $this->image_dst_type = ''; - - $this->uploaded = true; - $this->no_upload_check = false; - $this->processed = true; - $this->error = ''; - $this->log = ''; - $this->allowed = []; - $this->forbidden = []; - $this->file_is_image = false; - $this->init(); - $info = null; - $mime_from_browser = null; - - // sets default language - $this->translation = []; - $this->translation['file_error'] = 'File error. Please try again.'; - $this->translation['local_file_missing'] = 'Local file doesn\'t exist.'; - $this->translation['local_file_not_readable'] = 'Local file is not readable.'; - $this->translation['uploaded_too_big_ini'] = 'File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini).'; - $this->translation['uploaded_too_big_html'] = 'File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form).'; - $this->translation['uploaded_partial'] = 'File upload error (the uploaded file was only partially uploaded).'; - $this->translation['uploaded_missing'] = 'File upload error (no file was uploaded).'; - $this->translation['uploaded_no_tmp_dir'] = 'File upload error (missing a temporary folder).'; - $this->translation['uploaded_cant_write'] = 'File upload error (failed to write file to disk).'; - $this->translation['uploaded_err_extension'] = 'File upload error (file upload stopped by extension).'; - $this->translation['uploaded_unknown'] = 'File upload error (unknown error code).'; - $this->translation['try_again'] = 'File upload error. Please try again.'; - $this->translation['file_too_big'] = 'File too big.'; - $this->translation['no_mime'] = 'MIME type can\'t be detected.'; - $this->translation['incorrect_file'] = 'Incorrect type of file.'; - $this->translation['image_too_wide'] = 'Image too wide.'; - $this->translation['image_too_narrow'] = 'Image too narrow.'; - $this->translation['image_too_high'] = 'Image too tall.'; - $this->translation['image_too_short'] = 'Image too short.'; - $this->translation['ratio_too_high'] = 'Image ratio too high (image too wide).'; - $this->translation['ratio_too_low'] = 'Image ratio too low (image too high).'; - $this->translation['too_many_pixels'] = 'Image has too many pixels.'; - $this->translation['not_enough_pixels'] = 'Image has not enough pixels.'; - $this->translation['file_not_uploaded'] = 'File not uploaded. Can\'t carry on a process.'; - $this->translation['already_exists'] = '%s already exists. Please change the file name.'; - $this->translation['temp_file_missing'] = 'No correct temp source file. Can\'t carry on a process.'; - $this->translation['source_missing'] = 'No correct uploaded source file. Can\'t carry on a process.'; - $this->translation['destination_dir'] = 'Destination directory can\'t be created. Can\'t carry on a process.'; - $this->translation['destination_dir_missing'] = 'Destination directory doesn\'t exist. Can\'t carry on a process.'; - $this->translation['destination_path_not_dir'] = 'Destination path is not a directory. Can\'t carry on a process.'; - $this->translation['destination_dir_write'] = 'Destination directory can\'t be made writeable. Can\'t carry on a process.'; - $this->translation['destination_path_write'] = 'Destination path is not a writeable. Can\'t carry on a process.'; - $this->translation['temp_file'] = 'Can\'t create the temporary file. Can\'t carry on a process.'; - $this->translation['source_not_readable'] = 'Source file is not readable. Can\'t carry on a process.'; - $this->translation['no_create_support'] = 'No create from %s support.'; - $this->translation['create_error'] = 'Error in creating %s image from source.'; - $this->translation['source_invalid'] = 'Can\'t read image source. Not an image?.'; - $this->translation['gd_missing'] = 'GD doesn\'t seem to be present.'; - $this->translation['watermark_no_create_support'] = 'No create from %s support, can\'t read watermark.'; - $this->translation['watermark_create_error'] = 'No %s read support, can\'t create watermark.'; - $this->translation['watermark_invalid'] = 'Unknown image format, can\'t read watermark.'; - $this->translation['file_create'] = 'No %s create support.'; - $this->translation['no_conversion_type'] = 'No conversion type defined.'; - $this->translation['copy_failed'] = 'Error copying file on the server. copy() failed.'; - $this->translation['reading_failed'] = 'Error reading the file.'; - - // determines the language - $this->lang = $lang; - if ($this->lang != 'en_GB' && file_exists(dirname(__FILE__) . '/lang') && file_exists(dirname(__FILE__) . '/lang/class.upload.' . $lang . '.php')) { - $translation = null; - include(dirname(__FILE__) . '/lang/class.upload.' . $lang . '.php'); - if (is_array($translation)) { - $this->translation = array_merge($this->translation, $translation); - } else { - $this->lang = 'en_GB'; - } - } - - // determines the supported MIME types, and matching image format - $this->image_supported = []; - if ($this->gdversion()) { - if (imagetypes() & IMG_GIF) { - $this->image_supported['image/gif'] = 'gif'; - } - if (imagetypes() & IMG_JPG) { - $this->image_supported['image/jpg'] = 'jpg'; - $this->image_supported['image/jpeg'] = 'jpg'; - $this->image_supported['image/pjpeg'] = 'jpg'; - } - if (imagetypes() & IMG_PNG) { - $this->image_supported['image/png'] = 'png'; - $this->image_supported['image/x-png'] = 'png'; - } - if (imagetypes() & IMG_WBMP) { - $this->image_supported['image/bmp'] = 'bmp'; - $this->image_supported['image/x-ms-bmp'] = 'bmp'; - $this->image_supported['image/x-windows-bmp'] = 'bmp'; - } - } - - // display some system information - if (empty($this->log)) { - $this->log .= 'system information
'; - if (function_exists('ini_get_all')) { - $inis = ini_get_all(); - $open_basedir = (array_key_exists('open_basedir', $inis) && array_key_exists('local_value', $inis['open_basedir']) && !empty($inis['open_basedir']['local_value'])) ? $inis['open_basedir']['local_value'] : false; - } else { - $open_basedir = false; - } - $gd = $this->gdversion() ? $this->gdversion(true) : 'GD not present'; - $supported = trim((in_array('png', $this->image_supported) ? 'png' : '') . ' ' . (in_array('jpg', $this->image_supported) ? 'jpg' : '') . ' ' . (in_array('gif', $this->image_supported) ? 'gif' : '') . ' ' . (in_array('bmp', $this->image_supported) ? 'bmp' : '')); - $this->log .= '- class version : ' . $this->version . '
'; - $this->log .= '- operating system : ' . PHP_OS . '
'; - $this->log .= '- PHP version : ' . PHP_VERSION . '
'; - $this->log .= '- GD version : ' . $gd . '
'; - $this->log .= '- supported image types : ' . (!empty($supported) ? $supported : 'none') . '
'; - $this->log .= '- open_basedir : ' . (!empty($open_basedir) ? $open_basedir : 'no restriction') . '
'; - $this->log .= '- upload_max_filesize : ' . $this->file_max_size_raw . ' (' . $this->file_max_size . ' bytes)
'; - $this->log .= '- language : ' . $this->lang . '
'; - } - - if (!$file) { - $this->uploaded = false; - $this->error = $this->translate('file_error'); - } - - // check if we sent a local filename or a PHP stream rather than a $_FILE element - if (!is_array($file)) { - if (empty($file)) { - $this->uploaded = false; - $this->error = $this->translate('file_error'); - } else { - if (substr($file, 0, 4) == 'php:') { - // this is a local filename, i.e.not uploaded - $file = preg_replace('/^php:(.*)/i', '$1', $file); - if (!$file) { - $file = $_SERVER['HTTP_X_FILE_NAME']; - } - if (!$file) { - $file = 'unknown'; - } - $this->log .= '' . $this->translate("source is a PHP stream") . ' ' . $file . '
'; - $this->no_upload_check = true; - - $this->log .= '- this is a PHP stream, requires a temp file ... '; - $hash = $this->temp_dir() . md5($file . rand(1, 1000)); - if (file_put_contents($hash, file_get_contents('php://input'))) { - $this->file_src_pathname = $hash; - $this->log .= ' file created
'; - $this->log .= '    temp file is: ' . $this->file_src_pathname . '
'; - } else { - $this->log .= ' failed
'; - $this->uploaded = false; - $this->error = $this->translate('temp_file'); - } - - if ($this->uploaded) { - $this->file_src_name = $file; - $this->log .= '- local file OK
'; - preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); - if (is_array($extension) && sizeof($extension) > 0) { - $this->file_src_name_ext = strtolower($extension[1]); - $this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext))) - 1); - } else { - $this->file_src_name_ext = ''; - $this->file_src_name_body = $this->file_src_name; - } - $this->file_src_size = (file_exists($this->file_src_pathname) ? filesize($this->file_src_pathname) : 0); - } - $this->file_src_error = 0; - } else { - // this is a local filename, i.e.not uploaded - $this->log .= '' . $this->translate("source is a local file") . ' ' . $file . '
'; - $this->no_upload_check = true; - - if ($this->uploaded && !file_exists($file)) { - $this->uploaded = false; - $this->error = $this->translate('local_file_missing'); - } - - if ($this->uploaded && !is_readable($file)) { - $this->uploaded = false; - $this->error = $this->translate('local_file_not_readable'); - } - - if ($this->uploaded) { - $this->file_src_pathname = $file; - $this->file_src_name = basename($file); - $this->log .= '- local file OK
'; - preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); - if (is_array($extension) && sizeof($extension) > 0) { - $this->file_src_name_ext = strtolower($extension[1]); - $this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext))) - 1); - } else { - $this->file_src_name_ext = ''; - $this->file_src_name_body = $this->file_src_name; - } - $this->file_src_size = (file_exists($this->file_src_pathname) ? filesize($this->file_src_pathname) : 0); - } - $this->file_src_error = 0; - } - } - } else { - // this is an element from $_FILE, i.e. an uploaded file - $this->log .= 'source is an uploaded file
'; - if ($this->uploaded) { - $this->file_src_error = trim($file['error']); - switch ($this->file_src_error) { - case UPLOAD_ERR_OK: - // all is OK - $this->log .= '- upload OK
'; - break; - case UPLOAD_ERR_INI_SIZE: - $this->uploaded = false; - $this->error = $this->translate('uploaded_too_big_ini'); - break; - case UPLOAD_ERR_FORM_SIZE: - $this->uploaded = false; - $this->error = $this->translate('uploaded_too_big_html'); - break; - case UPLOAD_ERR_PARTIAL: - $this->uploaded = false; - $this->error = $this->translate('uploaded_partial'); - break; - case UPLOAD_ERR_NO_FILE: - $this->uploaded = false; - $this->error = $this->translate('uploaded_missing'); - break; - case @UPLOAD_ERR_NO_TMP_DIR: - $this->uploaded = false; - $this->error = $this->translate('uploaded_no_tmp_dir'); - break; - case @UPLOAD_ERR_CANT_WRITE: - $this->uploaded = false; - $this->error = $this->translate('uploaded_cant_write'); - break; - case @UPLOAD_ERR_EXTENSION: - $this->uploaded = false; - $this->error = $this->translate('uploaded_err_extension'); - break; - default: - $this->uploaded = false; - $this->error = $this->translate('uploaded_unknown') . ' (' . $this->file_src_error . ')'; - } - } - - if ($this->uploaded) { - $this->file_src_pathname = $file['tmp_name']; - $this->file_src_name = $file['name']; - if ($this->file_src_name == '') { - $this->uploaded = false; - $this->error = $this->translate('try_again'); - } - } - - if ($this->uploaded) { - $this->log .= '- file name OK
'; - preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); - if (is_array($extension) && sizeof($extension) > 0) { - $this->file_src_name_ext = strtolower($extension[1]); - $this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext))) - 1); - } else { - $this->file_src_name_ext = ''; - $this->file_src_name_body = $this->file_src_name; - } - $this->file_src_size = $file['size']; - $mime_from_browser = $file['type']; - } - } - - if ($this->uploaded) { - $this->log .= 'determining MIME type
'; - $this->file_src_mime = null; - - // checks MIME type with Fileinfo PECL extension - if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === false) { - if ($this->mime_fileinfo) { - $this->log .= '- Checking MIME type with Fileinfo PECL extension
'; - if (function_exists('finfo_open')) { - $path = null; - if ($this->mime_fileinfo !== '') { - if ($this->mime_fileinfo === true) { - if (getenv('MAGIC') === false) { - if (substr(PHP_OS, 0, 3) == 'WIN') { - $path = realpath(ini_get('extension_dir') . '/../') . '/extras/magic'; - $this->log .= '    MAGIC path defaults to ' . $path . '
'; - } - } else { - $path = getenv('MAGIC'); - $this->log .= '    MAGIC path is set to ' . $path . ' from MAGIC variable
'; - } - } else { - $path = $this->mime_fileinfo; - $this->log .= '    MAGIC path is set to ' . $path . '
'; - } - } - if ($path) { - $f = @finfo_open(FILEINFO_MIME, $path); - } else { - $this->log .= '    MAGIC path will not be used
'; - $f = @finfo_open(FILEINFO_MIME); - } - if (is_resource($f)) { - $mime = finfo_file($f, realpath($this->file_src_pathname)); - finfo_close($f); - $this->file_src_mime = $mime; - $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by Fileinfo PECL extension
'; - if (preg_match("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", $this->file_src_mime)) { - $this->file_src_mime = preg_replace("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", '$1/$2', $this->file_src_mime); - $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; - } else { - $this->file_src_mime = null; - } - } else { - $this->log .= '    Fileinfo PECL extension failed (finfo_open)
'; - } - } else { - if (@class_exists('finfo')) { - $f = new finfo(FILEINFO_MIME); - if ($f) { - $this->file_src_mime = $f->file(realpath($this->file_src_pathname)); - $this->log .= '- MIME type detected as ' . $this->file_src_mime . ' by Fileinfo PECL extension
'; - if (preg_match("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", $this->file_src_mime)) { - $this->file_src_mime = preg_replace("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", '$1/$2', $this->file_src_mime); - $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; - } else { - $this->file_src_mime = null; - } - } else { - $this->log .= '    Fileinfo PECL extension failed (finfo)
'; - } - } else { - $this->log .= '    Fileinfo PECL extension not available
'; - } - } - } else { - $this->log .= '- Fileinfo PECL extension deactivated
'; - } - } - - // checks MIME type with shell if unix access is authorized - if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === false) { - if ($this->mime_file) { - $this->log .= '- Checking MIME type with UNIX file() command
'; - if (substr(PHP_OS, 0, 3) != 'WIN') { - if (function_exists('exec') && function_exists('escapeshellarg') && !extension_loaded('suhosin')) { - if (strlen($mime = @exec("file -bi " . escapeshellarg($this->file_src_pathname))) != 0) { - $this->file_src_mime = trim($mime); - $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by UNIX file() command
'; - if (preg_match("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", $this->file_src_mime)) { - $this->file_src_mime = preg_replace("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", '$1/$2', $this->file_src_mime); - $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; - } else { - $this->file_src_mime = null; - } - } else { - $this->log .= '    UNIX file() command failed
'; - } - } else { - $this->log .= '    PHP exec() function is disabled
'; - } - } else { - $this->log .= '    UNIX file() command not availabled
'; - } - } else { - $this->log .= '- UNIX file() command is deactivated
'; - } - } - - // checks MIME type with mime_magic - if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === false) { - if ($this->mime_magic) { - $this->log .= '- Checking MIME type with mime.magic file (mime_content_type())
'; - if (function_exists('mime_content_type')) { - $this->file_src_mime = mime_content_type($this->file_src_pathname); - $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by mime_content_type()
'; - if (preg_match("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", $this->file_src_mime)) { - $this->file_src_mime = preg_replace("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", '$1/$2', $this->file_src_mime); - $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; - } else { - $this->file_src_mime = null; - } - } else { - $this->log .= '    mime_content_type() is not available
'; - } - } else { - $this->log .= '- mime.magic file (mime_content_type()) is deactivated
'; - } - } - - // checks MIME type with getimagesize() - if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === false) { - if ($this->mime_getimagesize) { - $this->log .= '- Checking MIME type with getimagesize()
'; - $info = getimagesize($this->file_src_pathname); - if (is_array($info) && array_key_exists('mime', $info)) { - $this->file_src_mime = trim($info['mime']); - if (empty($this->file_src_mime)) { - $this->log .= '    MIME empty, guessing from type
'; - $mime = (is_array($info) && array_key_exists(2, $info) ? $info[2] : null); // 1 = GIF, 2 = JPG, 3 = PNG - $this->file_src_mime = ($mime == IMAGETYPE_GIF ? 'image/gif' : ($mime == IMAGETYPE_JPEG ? 'image/jpeg' : ($mime == IMAGETYPE_PNG ? 'image/png' : ($mime == IMAGETYPE_BMP ? 'image/bmp' : null)))); - } - $this->log .= '    MIME type detected as ' . $this->file_src_mime . ' by PHP getimagesize() function
'; - if (preg_match("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", $this->file_src_mime)) { - $this->file_src_mime = preg_replace("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", '$1/$2', $this->file_src_mime); - $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; - } else { - $this->file_src_mime = null; - } - } else { - $this->log .= '    getimagesize() failed
'; - } - } else { - $this->log .= '- getimagesize() is deactivated
'; - } - } - - // default to MIME from browser (or Flash) - if (!empty($mime_from_browser) && !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime)) { - $this->file_src_mime = $mime_from_browser; - $this->log .= '- MIME type detected as ' . $this->file_src_mime . ' by browser
'; - if (preg_match("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", $this->file_src_mime)) { - $this->file_src_mime = preg_replace("/^([\.\w-]+)\/([\.\w-]+)(.*)$/i", '$1/$2', $this->file_src_mime); - $this->log .= '- MIME validated as ' . $this->file_src_mime . '
'; - } else { - $this->file_src_mime = null; - } - } - - // we need to work some magic if we upload via Flash - if ($this->file_src_mime == 'application/octet-stream' || !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === false) { - if ($this->file_src_mime == 'application/octet-stream') { - $this->log .= '- Flash may be rewriting MIME as application/octet-stream
'; - } - $this->log .= '- Try to guess MIME type from file extension (' . $this->file_src_name_ext . '): '; - if (array_key_exists($this->file_src_name_ext, $this->mime_types)) { - $this->file_src_mime = $this->mime_types[$this->file_src_name_ext]; - } - if ($this->file_src_mime == 'application/octet-stream') { - $this->log .= 'doesn\'t look like anything known
'; - } else { - $this->log .= 'MIME type set to ' . $this->file_src_mime . '
'; - } - } - - if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === false) { - $this->log .= '- MIME type couldn\'t be detected! (' . (string)$this->file_src_mime . ')
'; - } - - // determine whether the file is an image - if ($this->file_src_mime && is_string($this->file_src_mime) && !empty($this->file_src_mime) && array_key_exists($this->file_src_mime, $this->image_supported)) { - $this->file_is_image = true; - $this->image_src_type = $this->image_supported[$this->file_src_mime]; - } - - // if the file is an image, we gather some useful data - if ($this->file_is_image) { - if ($h = fopen($this->file_src_pathname, 'r')) { - fclose($h); - $info = getimagesize($this->file_src_pathname); - if (is_array($info)) { - $this->image_src_x = $info[0]; - $this->image_src_y = $info[1]; - $this->image_dst_x = $this->image_src_x; - $this->image_dst_y = $this->image_src_y; - $this->image_src_pixels = $this->image_src_x * $this->image_src_y; - $this->image_src_bits = array_key_exists('bits', $info) ? $info['bits'] : null; - } else { - $this->file_is_image = false; - $this->uploaded = false; - $this->log .= '- can\'t retrieve image information, image may have been tampered with
'; - $this->error = $this->translate('source_invalid'); - } - } else { - $this->log .= '- can\'t read source file directly. open_basedir restriction in place?
'; - } - } - - $this->log .= 'source variables
'; - $this->log .= '- You can use all these before calling process()
'; - $this->log .= '    file_src_name : ' . $this->file_src_name . '
'; - $this->log .= '    file_src_name_body : ' . $this->file_src_name_body . '
'; - $this->log .= '    file_src_name_ext : ' . $this->file_src_name_ext . '
'; - $this->log .= '    file_src_pathname : ' . $this->file_src_pathname . '
'; - $this->log .= '    file_src_mime : ' . $this->file_src_mime . '
'; - $this->log .= '    file_src_size : ' . $this->file_src_size . ' (max= ' . $this->file_max_size . ')
'; - $this->log .= '    file_src_error : ' . $this->file_src_error . '
'; - - if ($this->file_is_image) { - $this->log .= '- source file is an image
'; - $this->log .= '    image_src_x : ' . $this->image_src_x . '
'; - $this->log .= '    image_src_y : ' . $this->image_src_y . '
'; - $this->log .= '    image_src_pixels : ' . $this->image_src_pixels . '
'; - $this->log .= '    image_src_type : ' . $this->image_src_type . '
'; - $this->log .= '    image_src_bits : ' . $this->image_src_bits . '
'; - } - } - } - - /** - * Returns the version of GD - * - * @access public - * - * @param boolean $full Optional flag to get precise version - * - * @return float GD version - */ - function gdversion($full = false) - { - static $gd_version = null; - static $gd_full_version = null; - if ($gd_version === null) { - if (function_exists('gd_info')) { - $gd = gd_info(); - $gd = $gd["GD Version"]; - $regex = "/([\d\.]+)/i"; - } else { - ob_start(); - phpinfo(8); - $gd = ob_get_contents(); - ob_end_clean(); - $regex = "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i"; - } - if (preg_match($regex, $gd, $m)) { - $gd_full_version = (string)$m[1]; - $gd_version = (float)$m[1]; - } else { - $gd_full_version = 'none'; - $gd_version = 0; - } - } - if ($full) { - return $gd_full_version; - } else { - return $gd_version; - } - } - - /** - * Creates directories recursively - * - * @access private - * - * @param string $path Path to create - * @param integer $mode Optional permissions - * - * @return boolean Success - */ - function rmkdir($path, $mode = 0777) - { - return is_dir($path) || ($this->rmkdir(dirname($path), $mode) && $this->_mkdir($path, $mode)); - } - - /** - * Creates directory - * - * @access private - * - * @param string $path Path to create - * @param integer $mode Optional permissions - * - * @return boolean Success - */ - function _mkdir($path, $mode = 0777) - { - $old = umask(0); - $res = @mkdir($path, $mode); - umask($old); - - return $res; - } - - /** - * Translate error messages - * - * @access private - * - * @param string $str Message to translate - * @param array $tokens Optional token values - * - * @return string Translated string - */ - function translate($str, $tokens = []) - { - if (array_key_exists($str, $this->translation)) { - $str = $this->translation[$str]; - } - if (is_array($tokens) && sizeof($tokens) > 0) { - $str = vsprintf($str, $tokens); - } - - return $str; - } - - /** - * Returns the temp directory - * - * @access private - * @return string Temp directory string - */ - function temp_dir() - { - $dir = ''; - if (function_exists('sys_get_temp_dir')) { - $dir = sys_get_temp_dir(); - } - if (!$dir && $tmp = getenv('TMP')) { - $dir = $tmp; - } - if (!$dir && $tmp = getenv('TEMP')) { - $dir = $tmp; - } - if (!$dir && $tmp = getenv('TMPDIR')) { - $dir = $tmp; - } - if (!$dir) { - $tmp = tempnam(__FILE__, ''); - if (file_exists($tmp)) { - unlink($tmp); - $dir = dirname($tmp); - } - } - if (!$dir) { - return ''; - } - $slash = (strtolower(substr(PHP_OS, 0, 3)) === 'win' ? '\\' : '/'); - if (substr($dir, -1) != $slash) { - $dir = $dir . $slash; - } - - return $dir; - } - - /** - * Decodes colors - * - * @access private - * - * @param string $color Color string - * - * @return array RGB colors - */ - function getcolors($color) - { - $color = str_replace('#', '', $color); - if (strlen($color) == 3) { - $color = str_repeat(substr($color, 0, 1), 2) . str_repeat(substr($color, 1, 1), 2) . str_repeat(substr($color, 2, 1), 2); - } - $r = sscanf($color, "%2x%2x%2x"); - $red = (is_array($r) && array_key_exists(0, $r) && is_numeric($r[0]) ? $r[0] : 0); - $green = (is_array($r) && array_key_exists(1, $r) && is_numeric($r[1]) ? $r[1] : 0); - $blue = (is_array($r) && array_key_exists(2, $r) && is_numeric($r[2]) ? $r[2] : 0); - - return [$red, $green, $blue]; - } - - /** - * Decodes sizes - * - * @access private - * - * @param string $size Size in bytes, or shorthand byte options - * - * @return integer Size in bytes - */ - function getsize($size) - { - $last = strtolower($size{strlen($size) - 1}); - switch ($last) { - case 'g': - $size *= 1024; - case 'm': - $size *= 1024; - case 'k': - $size *= 1024; - } - - return $size; - } - - /** - * Decodes offsets - * - * @access private - * - * @param misc $offsets Offsets, as an integer, a string or an array - * @param integer $x Reference picture width - * @param integer $y Reference picture height - * @param boolean $round Round offsets before returning them - * @param boolean $negative Allow negative offsets to be returned - * - * @return array Array of four offsets (TRBL) - */ - function getoffsets($offsets, $x, $y, $round = true, $negative = true) - { - if (!is_array($offsets)) { - $offsets = explode(' ', $offsets); - } - if (sizeof($offsets) == 4) { - $ct = $offsets[0]; - $cr = $offsets[1]; - $cb = $offsets[2]; - $cl = $offsets[3]; - } else { - if (sizeof($offsets) == 2) { - $ct = $offsets[0]; - $cr = $offsets[1]; - $cb = $offsets[0]; - $cl = $offsets[1]; - } else { - $ct = $offsets[0]; - $cr = $offsets[0]; - $cb = $offsets[0]; - $cl = $offsets[0]; - } - } - if (strpos($ct, '%') > 0) { - $ct = $y * (str_replace('%', '', $ct) / 100); - } - if (strpos($cr, '%') > 0) { - $cr = $x * (str_replace('%', '', $cr) / 100); - } - if (strpos($cb, '%') > 0) { - $cb = $y * (str_replace('%', '', $cb) / 100); - } - if (strpos($cl, '%') > 0) { - $cl = $x * (str_replace('%', '', $cl) / 100); - } - if (strpos($ct, 'px') > 0) { - $ct = str_replace('px', '', $ct); - } - if (strpos($cr, 'px') > 0) { - $cr = str_replace('px', '', $cr); - } - if (strpos($cb, 'px') > 0) { - $cb = str_replace('px', '', $cb); - } - if (strpos($cl, 'px') > 0) { - $cl = str_replace('px', '', $cl); - } - $ct = (int)$ct; - $cr = (int)$cr; - $cb = (int)$cb; - $cl = (int)$cl; - if ($round) { - $ct = round($ct); - $cr = round($cr); - $cb = round($cb); - $cl = round($cl); - } - if (!$negative) { - if ($ct < 0) { - $ct = 0; - } - if ($cr < 0) { - $cr = 0; - } - if ($cb < 0) { - $cb = 0; - } - if ($cl < 0) { - $cl = 0; - } - } - - return [$ct, $cr, $cb, $cl]; - } - - /** - * Creates a container image - * - * @access private - * - * @param integer $x Width - * @param integer $y Height - * @param boolean $fill Optional flag to draw the background color or not - * @param boolean $trsp Optional flag to set the background to be transparent - * - * @return resource Container image - */ - function imagecreatenew($x, $y, $fill = true, $trsp = false) - { - if ($x < 1) { - $x = 1; - } - if ($y < 1) { - $y = 1; - } - if ($this->gdversion() >= 2 && !$this->image_is_palette) { - // create a true color image - $dst_im = imagecreatetruecolor($x, $y); - // this preserves transparency in PNGs, in true color - if (empty($this->image_background_color) || $trsp) { - imagealphablending($dst_im, false); - imagefilledrectangle($dst_im, 0, 0, $x, $y, imagecolorallocatealpha($dst_im, 0, 0, 0, 127)); - } - } else { - // creates a palette image - $dst_im = imagecreate($x, $y); - // preserves transparency for palette images, if the original image has transparency - if (($fill && $this->image_is_transparent && empty($this->image_background_color)) || $trsp) { - imagefilledrectangle($dst_im, 0, 0, $x, $y, $this->image_transparent_color); - imagecolortransparent($dst_im, $this->image_transparent_color); - } - } - // fills with background color if any is set - if ($fill && !empty($this->image_background_color) && !$trsp) { - list($red, $green, $blue) = $this->getcolors($this->image_background_color); - $background_color = imagecolorallocate($dst_im, $red, $green, $blue); - imagefilledrectangle($dst_im, 0, 0, $x, $y, $background_color); - } - - return $dst_im; - } - - /** - * Transfers an image from the container to the destination image - * - * @access private - * - * @param resource $src_im Container image - * @param resource $dst_im Destination image - * - * @return resource Destination image - */ - function imagetransfer($src_im, $dst_im) - { - if (is_resource($dst_im)) { - imagedestroy($dst_im); - } - $dst_im = &$src_im; - - return $dst_im; - } - - /** - * Merges two images - * - * If the output format is PNG, then we do it pixel per pixel to retain the alpha channel - * - * @access private - * - * @param $dst_im - * @param $src_im - * @param int $dst_x x-coordinate of destination point - * @param int $dst_y y-coordinate of destination point - * @param int $src_x x-coordinate of source point - * @param int $src_y y-coordinate of source point - * @param int $src_w Source width - * @param int $src_h Source height - * @param int $pct Optional percentage of the overlay, between 0 and 100 (default: 100) - * - * @return bool Destination image - */ - function imagecopymergealpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct = 0) - { - $dst_x = (int)$dst_x; - $dst_y = (int)$dst_y; - $src_x = (int)$src_x; - $src_y = (int)$src_y; - $src_w = (int)$src_w; - $src_h = (int)$src_h; - $pct = (int)$pct; - $dst_w = imagesx($dst_im); - $dst_h = imagesy($dst_im); - - for ($y = $src_y; $y < $src_h; $y++) { - for ($x = $src_x; $x < $src_w; $x++) { - if ($x + $dst_x >= 0 && $x + $dst_x < $dst_w && $x + $src_x >= 0 && $x + $src_x < $src_w - && $y + $dst_y >= 0 && $y + $dst_y < $dst_h && $y + $src_y >= 0 && $y + $src_y < $src_h) { - $dst_pixel = imagecolorsforindex($dst_im, imagecolorat($dst_im, $x + $dst_x, $y + $dst_y)); - $src_pixel = imagecolorsforindex($src_im, imagecolorat($src_im, $x + $src_x, $y + $src_y)); - - $src_alpha = 1 - ($src_pixel['alpha'] / 127); - $dst_alpha = 1 - ($dst_pixel['alpha'] / 127); - $opacity = $src_alpha * $pct / 100; - if ($dst_alpha >= $opacity) { - $alpha = $dst_alpha; - } - if ($dst_alpha < $opacity) { - $alpha = $opacity; - } - if ($alpha > 1) { - $alpha = 1; - } - - if ($opacity > 0) { - $dst_red = round((($dst_pixel['red'] * $dst_alpha * (1 - $opacity)))); - $dst_green = round((($dst_pixel['green'] * $dst_alpha * (1 - $opacity)))); - $dst_blue = round((($dst_pixel['blue'] * $dst_alpha * (1 - $opacity)))); - $src_red = round((($src_pixel['red'] * $opacity))); - $src_green = round((($src_pixel['green'] * $opacity))); - $src_blue = round((($src_pixel['blue'] * $opacity))); - $red = round(($dst_red + $src_red) / ($dst_alpha * (1 - $opacity) + $opacity)); - $green = round(($dst_green + $src_green) / ($dst_alpha * (1 - $opacity) + $opacity)); - $blue = round(($dst_blue + $src_blue) / ($dst_alpha * (1 - $opacity) + $opacity)); - if ($red > 255) { - $red = 255; - } - if ($green > 255) { - $green = 255; - } - if ($blue > 255) { - $blue = 255; - } - $alpha = round((1 - $alpha) * 127); - $color = imagecolorallocatealpha($dst_im, $red, $green, $blue, $alpha); - imagesetpixel($dst_im, $x + $dst_x, $y + $dst_y, $color); - } - } - } - } - - return true; - } - - /** - * Actually uploads the file, and act on it according to the set processing class variables - * - * This function copies the uploaded file to the given location, eventually performing actions on it. - * Typically, you can call {@link process} several times for the same file, - * for instance to create a resized image and a thumbnail of the same file. - * The original uploaded file remains intact in its temporary location, so you can use {@link process} several - * times. You will be able to delete the uploaded file with {@link clean} when you have finished all your - * {@link process} calls. - * - * According to the processing class variables set in the calling file, the file can be renamed, - * and if it is an image, can be resized or converted. - * - * When the processing is completed, and the file copied to its new location, the - * processing class variables will be reset to their default value. - * This allows you to set new properties, and perform another {@link process} on the same uploaded file - * - * If the function is called with a null or empty argument, then it will return the content of the picture - * - * It will set {@link processed} (and {@link error} is an error occurred) - * - * @access public - * - * @param string $server_path Optional path location of the uploaded file, with an ending slash - * - * @return string Optional content of the image - */ - function process($server_path = null) - { - $this->error = ''; - $this->processed = true; - $return_mode = false; - $return_content = null; - - // clean up dst variables - $this->file_dst_path = ''; - $this->file_dst_pathname = ''; - $this->file_dst_name = ''; - $this->file_dst_name_body = ''; - $this->file_dst_name_ext = ''; - - // clean up some parameters - $this->file_max_size = $this->getsize($this->file_max_size); - $this->jpeg_size = $this->getsize($this->jpeg_size); - // some parameters are being deprecated, and replaced with others - if (is_null($this->image_overlay_opacity)) { - $this->image_overlay_opacity = $this->image_overlay_percent; - } - if ($this->image_text_opacity == 100) { - $this->image_text_opacity = $this->image_text_percent; - } - if ($this->image_text_background_opacity == 100) { - $this->image_text_background_opacity = $this->image_text_background_percent; - } - - // copy some variables as we need to keep them clean - $file_src_name = $this->file_src_name; - $file_src_name_body = $this->file_src_name_body; - $file_src_name_ext = $this->file_src_name_ext; - - if (!$this->uploaded) { - $this->error = $this->translate('file_not_uploaded'); - $this->processed = false; - } - - if ($this->processed) { - if (empty($server_path) || is_null($server_path)) { - $this->log .= 'process file and return the content
'; - $return_mode = true; - } else { - if (strtolower(substr(PHP_OS, 0, 3)) === 'win') { - if (substr($server_path, -1, 1) != '\\') { - $server_path = $server_path . '\\'; - } - } else { - if (substr($server_path, -1, 1) != '/') { - $server_path = $server_path . '/'; - } - } - $this->log .= 'process file to ' . $server_path . '
'; - } - } - - if ($this->processed) { - // checks file max size - if ($this->file_src_size > $this->file_max_size) { - $this->processed = false; - $this->error = $this->translate('file_too_big') . ' : ' . $this->file_src_size . ' > ' . $this->file_max_size; - } else { - $this->log .= '- file size OK
'; - } - } - - if ($this->processed) { - // if we have an image without extension, set it - if ($this->file_force_extension && $this->file_is_image && !$this->file_src_name_ext) { - $file_src_name_ext = $this->image_src_type; - } - // turn dangerous scripts into text files - if ($this->no_script) { - // if the file has no extension, we try to guess it from the MIME type - if ($this->file_force_extension && empty($file_src_name_ext)) { - if ($key = array_search($this->file_src_mime, $this->mime_types)) { - $file_src_name_ext = $key; - $file_src_name = $file_src_name_body . '.' . $file_src_name_ext; - $this->log .= '- file renamed as ' . $file_src_name_body . '.' . $file_src_name_ext . '!
'; - } - } - // if the file is text based, or has a dangerous extension, we rename it as .txt - if ((((substr($this->file_src_mime, 0, 5) == 'text/' && $this->file_src_mime != 'text/rtf') || strpos($this->file_src_mime, 'javascript') !== false) && (substr($file_src_name, -4) != '.txt')) - || preg_match('/\.(php|php5|php4|php3|phtml|pl|py|cgi|asp|js)$/i', $this->file_src_name) - || $this->file_force_extension && empty($file_src_name_ext)) { - $this->file_src_mime = 'text/plain'; - if ($this->file_src_name_ext) { - $file_src_name_body = $file_src_name_body . '.' . $this->file_src_name_ext; - } - $file_src_name_ext = 'txt'; - $file_src_name = $file_src_name_body . '.' . $file_src_name_ext; - $this->log .= '- script renamed as ' . $file_src_name_body . '.' . $file_src_name_ext . '!
'; - } - } - - if ($this->mime_check && empty($this->file_src_mime)) { - $this->processed = false; - $this->error = $this->translate('no_mime'); - } else { - if ($this->mime_check && !empty($this->file_src_mime) && strpos($this->file_src_mime, '/') !== false) { - list($m1, $m2) = explode('/', $this->file_src_mime); - $allowed = false; - // check wether the mime type is allowed - if (!is_array($this->allowed)) { - $this->allowed = [$this->allowed]; - } - foreach ($this->allowed as $k => $v) { - list($v1, $v2) = explode('/', $v); - if (($v1 == '*' && $v2 == '*') || ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) { - $allowed = true; - break; - } - } - // check wether the mime type is forbidden - if (!is_array($this->forbidden)) { - $this->forbidden = [$this->forbidden]; - } - foreach ($this->forbidden as $k => $v) { - list($v1, $v2) = explode('/', $v); - if (($v1 == '*' && $v2 == '*') || ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) { - $allowed = false; - break; - } - } - if (!$allowed) { - $this->processed = false; - $this->error = $this->translate('incorrect_file'); - } else { - $this->log .= '- file mime OK : ' . $this->file_src_mime . '
'; - } - } else { - $this->log .= '- file mime (not checked) : ' . $this->file_src_mime . '
'; - } - } - - // if the file is an image, we can check on its dimensions - // these checks are not available if open_basedir restrictions are in place - if ($this->file_is_image) { - if (is_numeric($this->image_src_x) && is_numeric($this->image_src_y)) { - $ratio = $this->image_src_x / $this->image_src_y; - if (!is_null($this->image_max_width) && $this->image_src_x > $this->image_max_width) { - $this->processed = false; - $this->error = $this->translate('image_too_wide'); - } - if (!is_null($this->image_min_width) && $this->image_src_x < $this->image_min_width) { - $this->processed = false; - $this->error = $this->translate('image_too_narrow'); - } - if (!is_null($this->image_max_height) && $this->image_src_y > $this->image_max_height) { - $this->processed = false; - $this->error = $this->translate('image_too_high'); - } - if (!is_null($this->image_min_height) && $this->image_src_y < $this->image_min_height) { - $this->processed = false; - $this->error = $this->translate('image_too_short'); - } - if (!is_null($this->image_max_ratio) && $ratio > $this->image_max_ratio) { - $this->processed = false; - $this->error = $this->translate('ratio_too_high'); - } - if (!is_null($this->image_min_ratio) && $ratio < $this->image_min_ratio) { - $this->processed = false; - $this->error = $this->translate('ratio_too_low'); - } - if (!is_null($this->image_max_pixels) && $this->image_src_pixels > $this->image_max_pixels) { - $this->processed = false; - $this->error = $this->translate('too_many_pixels'); - } - if (!is_null($this->image_min_pixels) && $this->image_src_pixels < $this->image_min_pixels) { - $this->processed = false; - $this->error = $this->translate('not_enough_pixels'); - } - } else { - $this->log .= '- no image properties available, can\'t enforce dimension checks : ' . $this->file_src_mime . '
'; - } - } - } - - if ($this->processed) { - $this->file_dst_path = $server_path; - - // repopulate dst variables from src - $this->file_dst_name = $file_src_name; - $this->file_dst_name_body = $file_src_name_body; - $this->file_dst_name_ext = $file_src_name_ext; - if ($this->file_overwrite) { - $this->file_auto_rename = false; - } - - if ($this->image_convert && $this->file_is_image) { // if we convert as an image - if ($this->file_src_name_ext) { - $this->file_dst_name_ext = $this->image_convert; - } - $this->log .= '- new file name ext : ' . $this->image_convert . '
'; - } - if (!is_null($this->file_new_name_body)) { // rename file body - $this->file_dst_name_body = $this->file_new_name_body; - $this->log .= '- new file name body : ' . $this->file_new_name_body . '
'; - } - if (!is_null($this->file_new_name_ext)) { // rename file ext - $this->file_dst_name_ext = $this->file_new_name_ext; - $this->log .= '- new file name ext : ' . $this->file_new_name_ext . '
'; - } - if (!is_null($this->file_name_body_add)) { // append a string to the name - $this->file_dst_name_body = $this->file_dst_name_body . $this->file_name_body_add; - $this->log .= '- file name body append : ' . $this->file_name_body_add . '
'; - } - if (!is_null($this->file_name_body_pre)) { // prepend a string to the name - $this->file_dst_name_body = $this->file_name_body_pre . $this->file_dst_name_body; - $this->log .= '- file name body prepend : ' . $this->file_name_body_pre . '
'; - } - if ($this->file_safe_name) { // formats the name - $this->file_dst_name_body = utf8_encode(strtr(utf8_decode($this->file_dst_name_body), utf8_decode('ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ'), 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy')); - $this->file_dst_name_body = strtr($this->file_dst_name_body, [ - 'Þ' => 'TH', - 'þ' => 'th', - 'Ð' => 'DH', - 'ð' => 'dh', - 'ß' => 'ss', - 'Œ' => 'OE', - 'œ' => 'oe', - 'Æ' => 'AE', - 'æ' => 'ae', - 'µ' => 'u', - ]); - $this->file_dst_name_body = preg_replace(['/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'], [ - '_', - '.', - '', - ], $this->file_dst_name_body); - $this->log .= '- file name safe format
'; - } - - $this->log .= '- destination variables
'; - if (empty($this->file_dst_path) || is_null($this->file_dst_path)) { - $this->log .= '    file_dst_path : n/a
'; - } else { - $this->log .= '    file_dst_path : ' . $this->file_dst_path . '
'; - } - $this->log .= '    file_dst_name_body : ' . $this->file_dst_name_body . '
'; - $this->log .= '    file_dst_name_ext : ' . $this->file_dst_name_ext . '
'; - - // do we do some image manipulation? - $image_manipulation = ($this->file_is_image && ( - $this->image_resize - || $this->image_convert != '' - || is_numeric($this->image_brightness) - || is_numeric($this->image_contrast) - || is_numeric($this->image_opacity) - || is_numeric($this->image_threshold) - || !empty($this->image_tint_color) - || !empty($this->image_overlay_color) - || $this->image_pixelate - || $this->image_unsharp - || !empty($this->image_text) - || $this->image_greyscale - || $this->image_negative - || !empty($this->image_watermark) - || $this->image_auto_rotate - || is_numeric($this->image_rotate) - || is_numeric($this->jpeg_size) - || !empty($this->image_flip) - || !empty($this->image_crop) - || !empty($this->image_precrop) - || !empty($this->image_border) - || !empty($this->image_border_transparent) - || $this->image_frame > 0 - || $this->image_bevel > 0 - || $this->image_reflection_height)); - - // set the destination file name - $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); - - if (!$return_mode) { - if (!$this->file_auto_rename) { - $this->log .= '- no auto_rename if same filename exists
'; - $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; - } else { - $this->log .= '- checking for auto_rename
'; - $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; - $body = $this->file_dst_name_body; - $ext = ''; - // if we have changed the extension, then we add our increment before - if ($file_src_name_ext != $this->file_src_name_ext) { - if (substr($this->file_dst_name_body, -1 - strlen($this->file_src_name_ext)) == '.' . $this->file_src_name_ext) { - $body = substr($this->file_dst_name_body, 0, strlen($this->file_dst_name_body) - 1 - strlen($this->file_src_name_ext)); - $ext = '.' . $this->file_src_name_ext; - } - } - $cpt = 1; - while (@file_exists($this->file_dst_pathname)) { - $this->file_dst_name_body = $body . '_' . $cpt . $ext; - $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); - $cpt++; - $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; - } - if ($cpt > 1) { - $this->log .= '    auto_rename to ' . $this->file_dst_name . '
'; - } - } - - $this->log .= '- destination file details
'; - $this->log .= '    file_dst_name : ' . $this->file_dst_name . '
'; - $this->log .= '    file_dst_pathname : ' . $this->file_dst_pathname . '
'; - - if ($this->file_overwrite) { - $this->log .= '- no overwrite checking
'; - } else { - if (@file_exists($this->file_dst_pathname)) { - $this->processed = false; - $this->error = $this->translate('already_exists', [$this->file_dst_name]); - } else { - $this->log .= '- ' . $this->file_dst_name . ' doesn\'t exist already
'; - } - } - } - } - - if ($this->processed) { - // if we have already moved the uploaded file, we use the temporary copy as source file, and check if it exists - if (!empty($this->file_src_temp)) { - $this->log .= '- use the temp file instead of the original file since it is a second process
'; - $this->file_src_pathname = $this->file_src_temp; - if (!file_exists($this->file_src_pathname)) { - $this->processed = false; - $this->error = $this->translate('temp_file_missing'); - } - // if we haven't a temp file, and that we do check on uploads, we use is_uploaded_file() - } else { - if (!$this->no_upload_check) { - if (!is_uploaded_file($this->file_src_pathname)) { - $this->processed = false; - $this->error = $this->translate('source_missing'); - } - // otherwise, if we don't check on uploaded files (local file for instance), we use file_exists() - } else { - if (!file_exists($this->file_src_pathname)) { - $this->processed = false; - $this->error = $this->translate('source_missing'); - } - } - } - - // checks if the destination directory exists, and attempt to create it - if (!$return_mode) { - if ($this->processed && !file_exists($this->file_dst_path)) { - if ($this->dir_auto_create) { - $this->log .= '- ' . $this->file_dst_path . ' doesn\'t exist. Attempting creation:'; - if (!$this->rmkdir($this->file_dst_path, $this->dir_chmod)) { - $this->log .= ' failed
'; - $this->processed = false; - $this->error = $this->translate('destination_dir'); - } else { - $this->log .= ' success
'; - } - } else { - $this->error = $this->translate('destination_dir_missing'); - } - } - - if ($this->processed && !is_dir($this->file_dst_path)) { - $this->processed = false; - $this->error = $this->translate('destination_path_not_dir'); - } - - // checks if the destination directory is writeable, and attempt to make it writeable - $hash = md5($this->file_dst_name_body . rand(1, 1000)); - if ($this->processed && !($f = @fopen($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''), 'a+'))) { - if ($this->dir_auto_chmod) { - $this->log .= '- ' . $this->file_dst_path . ' is not writeable. Attempting chmod:'; - if (!@chmod($this->file_dst_path, $this->dir_chmod)) { - $this->log .= ' failed
'; - $this->processed = false; - $this->error = $this->translate('destination_dir_write'); - } else { - $this->log .= ' success
'; - if (!($f = @fopen($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''), 'a+'))) { // we re-check - $this->processed = false; - $this->error = $this->translate('destination_dir_write'); - } else { - @fclose($f); - } - } - } else { - $this->processed = false; - $this->error = $this->translate('destination_path_write'); - } - } else { - if ($this->processed) { - @fclose($f); - } - @unlink($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : '')); - } - - // if we have an uploaded file, and if it is the first process, and if we can't access the file directly (open_basedir restriction) - // then we create a temp file that will be used as the source file in subsequent processes - // the third condition is there to check if the file is not accessible *directly* (it already has positively gone through is_uploaded_file(), so it exists) - if (!$this->no_upload_check && empty($this->file_src_temp) && !@file_exists($this->file_src_pathname)) { - $this->log .= '- attempting to use a temp file:'; - $hash = md5($this->file_dst_name_body . rand(1, 1000)); - if (move_uploaded_file($this->file_src_pathname, $this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''))) { - $this->file_src_pathname = $this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); - $this->file_src_temp = $this->file_src_pathname; - $this->log .= ' file created
'; - $this->log .= '    temp file is: ' . $this->file_src_temp . '
'; - } else { - $this->log .= ' failed
'; - $this->processed = false; - $this->error = $this->translate('temp_file'); - } - } - } - } - - if ($this->processed) { - // we do a quick check to ensure the file is really an image - // we can do this only now, as it would have failed before in case of open_basedir - if ($image_manipulation && !@getimagesize($this->file_src_pathname)) { - $this->log .= '- the file is not an image!
'; - $image_manipulation = false; - } - - if ($image_manipulation) { - // make sure GD doesn't complain too much - @ini_set("gd.jpeg_ignore_warning", 1); - - // checks if the source file is readable - if ($this->processed && !($f = @fopen($this->file_src_pathname, 'r'))) { - $this->processed = false; - $this->error = $this->translate('source_not_readable'); - } else { - @fclose($f); - } - - // we now do all the image manipulations - $this->log .= '- image resizing or conversion wanted
'; - if ($this->gdversion()) { - switch ($this->image_src_type) { - case 'jpg': - if (!function_exists('imagecreatefromjpeg')) { - $this->processed = false; - $this->error = $this->translate('no_create_support', ['JPEG']); - } else { - $image_src = @imagecreatefromjpeg($this->file_src_pathname); - if (!$image_src) { - $this->processed = false; - $this->error = $this->translate('create_error', ['JPEG']); - } else { - $this->log .= '- source image is JPEG
'; - } - } - break; - case 'png': - if (!function_exists('imagecreatefrompng')) { - $this->processed = false; - $this->error = $this->translate('no_create_support', ['PNG']); - } else { - $image_src = @imagecreatefrompng($this->file_src_pathname); - if (!$image_src) { - $this->processed = false; - $this->error = $this->translate('create_error', ['PNG']); - } else { - $this->log .= '- source image is PNG
'; - } - } - break; - case 'gif': - if (!function_exists('imagecreatefromgif')) { - $this->processed = false; - $this->error = $this->translate('no_create_support', ['GIF']); - } else { - $image_src = @imagecreatefromgif($this->file_src_pathname); - if (!$image_src) { - $this->processed = false; - $this->error = $this->translate('create_error', ['GIF']); - } else { - $this->log .= '- source image is GIF
'; - } - } - break; - case 'bmp': - if (!method_exists($this, 'imagecreatefrombmp')) { - $this->processed = false; - $this->error = $this->translate('no_create_support', ['BMP']); - } else { - $image_src = @$this->imagecreatefrombmp($this->file_src_pathname); - if (!$image_src) { - $this->processed = false; - $this->error = $this->translate('create_error', ['BMP']); - } else { - $this->log .= '- source image is BMP
'; - } - } - break; - default: - $this->processed = false; - $this->error = $this->translate('source_invalid'); - } - } else { - $this->processed = false; - $this->error = $this->translate('gd_missing'); - } - - if ($this->processed && $image_src) { - // we have to set image_convert if it is not already - if (empty($this->image_convert)) { - $this->log .= '- setting destination file type to ' . $this->image_src_type . '
'; - $this->image_convert = $this->image_src_type; - } - - if (!in_array($this->image_convert, $this->image_supported)) { - $this->image_convert = 'jpg'; - } - - // we set the default color to be the background color if we don't output in a transparent format - if ($this->image_convert != 'png' && $this->image_convert != 'gif' && !empty($this->image_default_color) && empty($this->image_background_color)) { - $this->image_background_color = $this->image_default_color; - } - if (!empty($this->image_background_color)) { - $this->image_default_color = $this->image_background_color; - } - if (empty($this->image_default_color)) { - $this->image_default_color = '#FFFFFF'; - } - - $this->image_src_x = imagesx($image_src); - $this->image_src_y = imagesy($image_src); - $gd_version = $this->gdversion(); - $ratio_crop = null; - - if (!imageistruecolor($image_src)) { // $this->image_src_type == 'gif' - $this->log .= '- image is detected as having a palette
'; - $this->image_is_palette = true; - $this->image_transparent_color = imagecolortransparent($image_src); - if ($this->image_transparent_color >= 0 && imagecolorstotal($image_src) > $this->image_transparent_color) { - $this->image_is_transparent = true; - $this->log .= '    palette image is detected as transparent
'; - } - // if the image has a palette (GIF), we convert it to true color, preserving transparency - $this->log .= '    convert palette image to true color
'; - $true_color = imagecreatetruecolor($this->image_src_x, $this->image_src_y); - imagealphablending($true_color, false); - imagesavealpha($true_color, true); - for ($x = 0; $x < $this->image_src_x; $x++) { - for ($y = 0; $y < $this->image_src_y; $y++) { - if ($this->image_transparent_color >= 0 && imagecolorat($image_src, $x, $y) == $this->image_transparent_color) { - imagesetpixel($true_color, $x, $y, 127 << 24); - } else { - $rgb = imagecolorsforindex($image_src, imagecolorat($image_src, $x, $y)); - imagesetpixel($true_color, $x, $y, ($rgb['alpha'] << 24) | ($rgb['red'] << 16) | ($rgb['green'] << 8) | $rgb['blue']); - } - } - } - $image_src = $this->imagetransfer($true_color, $image_src); - imagealphablending($image_src, false); - imagesavealpha($image_src, true); - $this->image_is_palette = false; - } - - $image_dst = &$image_src; - - // automatically pre-rotates the image according to EXIF data (JPEG only) - if ($this->image_auto_rotate && $this->image_src_type == 'jpg' && function_exists('exif_read_data')) { - $auto_flip = false; - $auto_rotate = 0; - $exif = @exif_read_data($this->file_src_pathname); - if (is_array($exif) && isset($exif['Orientation'])) { - $orientation = $exif['Orientation']; - switch ($orientation) { - case 1: - $this->log .= '- EXIF orientation = 1 : default
'; - break; - case 2: - $auto_flip = 'v'; - $this->log .= '- EXIF orientation = 2 : vertical flip
'; - break; - case 3: - $auto_rotate = 180; - $this->log .= '- EXIF orientation = 3 : 180 rotate left
'; - break; - case 4: - $auto_flip = 'h'; - $this->log .= '- EXIF orientation = 4 : horizontal flip
'; - break; - case 5: - $auto_flip = 'h'; - $auto_rotate = 90; - $this->log .= '- EXIF orientation = 5 : horizontal flip + 90 rotate right
'; - break; - case 6: - $auto_rotate = 90; - $this->log .= '- EXIF orientation = 6 : 90 rotate right
'; - break; - case 7: - $auto_flip = 'v'; - $auto_rotate = 90; - $this->log .= '- EXIF orientation = 7 : vertical flip + 90 rotate right
'; - break; - case 8: - $auto_rotate = 270; - $this->log .= '- EXIF orientation = 8 : 90 rotate left
'; - break; - default: - $this->log .= '- EXIF orientation = ' . $orientation . ' : unknown
'; - break; - } - } else { - $this->log .= '- EXIF data is invalid
'; - } - - // auto-flip image - if ($gd_version >= 2 && !empty($auto_flip)) { - $this->log .= '    auto-flip image : ' . $auto_flip . '
'; - $tmp = $this->imagecreatenew($this->image_src_x, $this->image_src_y); - for ($x = 0; $x < $this->image_src_x; $x++) { - for ($y = 0; $y < $this->image_src_y; $y++) { - if (strpos($auto_flip, 'v') !== false) { - imagecopy($tmp, $image_dst, $this->image_src_x - $x - 1, $y, $x, $y, 1, 1); - } else { - imagecopy($tmp, $image_dst, $x, $this->image_src_y - $y - 1, $x, $y, 1, 1); - } - } - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // auto-rotate image - if ($gd_version >= 2 && is_numeric($auto_rotate)) { - if (!in_array($auto_rotate, [0, 90, 180, 270])) { - $auto_rotate = 0; - } - if ($auto_rotate != 0) { - if ($auto_rotate == 90 || $auto_rotate == 270) { - $tmp = $this->imagecreatenew($this->image_src_y, $this->image_src_x); - } else { - $tmp = $this->imagecreatenew($this->image_src_x, $this->image_src_y); - } - $this->log .= '    auto-rotate image : ' . $auto_rotate . '
'; - for ($x = 0; $x < $this->image_src_x; $x++) { - for ($y = 0; $y < $this->image_src_y; $y++) { - if ($auto_rotate == 90) { - imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_src_y - $y - 1, 1, 1); - } else { - if ($auto_rotate == 180) { - imagecopy($tmp, $image_dst, $x, $y, $this->image_src_x - $x - 1, $this->image_src_y - $y - 1, 1, 1); - } else { - if ($auto_rotate == 270) { - imagecopy($tmp, $image_dst, $y, $x, $this->image_src_x - $x - 1, $y, 1, 1); - } else { - imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1); - } - } - } - } - } - if ($auto_rotate == 90 || $auto_rotate == 270) { - $t = $this->image_src_y; - $this->image_src_y = $this->image_src_x; - $this->image_src_x = $t; - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - } - } else { - if (!$this->image_auto_rotate) { - $this->log .= '- auto-rotate deactivated
'; - } else { - if (!$this->image_src_type == 'jpg') { - $this->log .= '- auto-rotate applies only to JPEG images
'; - } else { - if (!function_exists('exif_read_data')) { - $this->log .= '- auto-rotate requires function exif_read_data to be enabled
'; - } - } - } - } - - // pre-crop image, before resizing - if ((!empty($this->image_precrop))) { - list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_precrop, $this->image_src_x, $this->image_src_y, true, true); - $this->log .= '- pre-crop image : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '
'; - $this->image_src_x = $this->image_src_x - $cl - $cr; - $this->image_src_y = $this->image_src_y - $ct - $cb; - if ($this->image_src_x < 1) { - $this->image_src_x = 1; - } - if ($this->image_src_y < 1) { - $this->image_src_y = 1; - } - $tmp = $this->imagecreatenew($this->image_src_x, $this->image_src_y); - - // we copy the image into the recieving image - imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_src_x, $this->image_src_y); - - // if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent - if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0) { - // use the background color if present - if (!empty($this->image_background_color)) { - list($red, $green, $blue) = $this->getcolors($this->image_background_color); - $fill = imagecolorallocate($tmp, $red, $green, $blue); - } else { - $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); - } - // fills eventual negative margins - if ($ct < 0) { - imagefilledrectangle($tmp, 0, 0, $this->image_src_x, -$ct, $fill); - } - if ($cr < 0) { - imagefilledrectangle($tmp, $this->image_src_x + $cr, 0, $this->image_src_x, $this->image_src_y, $fill); - } - if ($cb < 0) { - imagefilledrectangle($tmp, 0, $this->image_src_y + $cb, $this->image_src_x, $this->image_src_y, $fill); - } - if ($cl < 0) { - imagefilledrectangle($tmp, 0, 0, -$cl, $this->image_src_y, $fill); - } - } - - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // resize image (and move image_src_x, image_src_y dimensions into image_dst_x, image_dst_y) - if ($this->image_resize) { - $this->log .= '- resizing...
'; - - if ($this->image_ratio_x) { - $this->log .= '    calculate x size
'; - $this->image_dst_x = round(($this->image_src_x * $this->image_y) / $this->image_src_y); - $this->image_dst_y = $this->image_y; - } else { - if ($this->image_ratio_y) { - $this->log .= '    calculate y size
'; - $this->image_dst_x = $this->image_x; - $this->image_dst_y = round(($this->image_src_y * $this->image_x) / $this->image_src_x); - } else { - if (is_numeric($this->image_ratio_pixels)) { - $this->log .= '    calculate x/y size to match a number of pixels
'; - $pixels = $this->image_src_y * $this->image_src_x; - $diff = sqrt($this->image_ratio_pixels / $pixels); - $this->image_dst_x = round($this->image_src_x * $diff); - $this->image_dst_y = round($this->image_src_y * $diff); - } else { - if ($this->image_ratio || $this->image_ratio_crop || $this->image_ratio_fill || $this->image_ratio_no_zoom_in || $this->image_ratio_no_zoom_out) { - $this->log .= '    check x/y sizes
'; - if ((!$this->image_ratio_no_zoom_in && !$this->image_ratio_no_zoom_out) - || ($this->image_ratio_no_zoom_in && ($this->image_src_x > $this->image_x || $this->image_src_y > $this->image_y)) - || ($this->image_ratio_no_zoom_out && $this->image_src_x < $this->image_x && $this->image_src_y < $this->image_y)) { - $this->image_dst_x = $this->image_x; - $this->image_dst_y = $this->image_y; - if ($this->image_ratio_crop) { - if (!is_string($this->image_ratio_crop)) { - $this->image_ratio_crop = ''; - } - $this->image_ratio_crop = strtolower($this->image_ratio_crop); - if (($this->image_src_x / $this->image_x) > ($this->image_src_y / $this->image_y)) { - $this->image_dst_y = $this->image_y; - $this->image_dst_x = intval($this->image_src_x * ($this->image_y / $this->image_src_y)); - $ratio_crop = []; - $ratio_crop['x'] = $this->image_dst_x - $this->image_x; - if (strpos($this->image_ratio_crop, 'l') !== false) { - $ratio_crop['l'] = 0; - $ratio_crop['r'] = $ratio_crop['x']; - } else { - if (strpos($this->image_ratio_crop, 'r') !== false) { - $ratio_crop['l'] = $ratio_crop['x']; - $ratio_crop['r'] = 0; - } else { - $ratio_crop['l'] = round($ratio_crop['x'] / 2); - $ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l']; - } - } - $this->log .= '    ratio_crop_x : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')
'; - if (is_null($this->image_crop)) { - $this->image_crop = [0, 0, 0, 0]; - } - } else { - $this->image_dst_x = $this->image_x; - $this->image_dst_y = intval($this->image_src_y * ($this->image_x / $this->image_src_x)); - $ratio_crop = []; - $ratio_crop['y'] = $this->image_dst_y - $this->image_y; - if (strpos($this->image_ratio_crop, 't') !== false) { - $ratio_crop['t'] = 0; - $ratio_crop['b'] = $ratio_crop['y']; - } else { - if (strpos($this->image_ratio_crop, 'b') !== false) { - $ratio_crop['t'] = $ratio_crop['y']; - $ratio_crop['b'] = 0; - } else { - $ratio_crop['t'] = round($ratio_crop['y'] / 2); - $ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t']; - } - } - $this->log .= '    ratio_crop_y : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')
'; - if (is_null($this->image_crop)) { - $this->image_crop = [0, 0, 0, 0]; - } - } - } else { - if ($this->image_ratio_fill) { - if (!is_string($this->image_ratio_fill)) { - $this->image_ratio_fill = ''; - } - $this->image_ratio_fill = strtolower($this->image_ratio_fill); - if (($this->image_src_x / $this->image_x) < ($this->image_src_y / $this->image_y)) { - $this->image_dst_y = $this->image_y; - $this->image_dst_x = intval($this->image_src_x * ($this->image_y / $this->image_src_y)); - $ratio_crop = []; - $ratio_crop['x'] = $this->image_dst_x - $this->image_x; - if (strpos($this->image_ratio_fill, 'l') !== false) { - $ratio_crop['l'] = 0; - $ratio_crop['r'] = $ratio_crop['x']; - } else { - if (strpos($this->image_ratio_fill, 'r') !== false) { - $ratio_crop['l'] = $ratio_crop['x']; - $ratio_crop['r'] = 0; - } else { - $ratio_crop['l'] = round($ratio_crop['x'] / 2); - $ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l']; - } - } - $this->log .= '    ratio_fill_x : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')
'; - if (is_null($this->image_crop)) { - $this->image_crop = [0, 0, 0, 0]; - } - } else { - $this->image_dst_x = $this->image_x; - $this->image_dst_y = intval($this->image_src_y * ($this->image_x / $this->image_src_x)); - $ratio_crop = []; - $ratio_crop['y'] = $this->image_dst_y - $this->image_y; - if (strpos($this->image_ratio_fill, 't') !== false) { - $ratio_crop['t'] = 0; - $ratio_crop['b'] = $ratio_crop['y']; - } else { - if (strpos($this->image_ratio_fill, 'b') !== false) { - $ratio_crop['t'] = $ratio_crop['y']; - $ratio_crop['b'] = 0; - } else { - $ratio_crop['t'] = round($ratio_crop['y'] / 2); - $ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t']; - } - } - $this->log .= '    ratio_fill_y : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')
'; - if (is_null($this->image_crop)) { - $this->image_crop = [0, 0, 0, 0]; - } - } - } else { - if (($this->image_src_x / $this->image_x) > ($this->image_src_y / $this->image_y)) { - $this->image_dst_x = $this->image_x; - $this->image_dst_y = intval($this->image_src_y * ($this->image_x / $this->image_src_x)); - } else { - $this->image_dst_y = $this->image_y; - $this->image_dst_x = intval($this->image_src_x * ($this->image_y / $this->image_src_y)); - } - } - } - } else { - $this->log .= '    doesn\'t calculate x/y sizes
'; - $this->image_dst_x = $this->image_src_x; - $this->image_dst_y = $this->image_src_y; - } - } else { - $this->log .= '    use plain sizes
'; - $this->image_dst_x = $this->image_x; - $this->image_dst_y = $this->image_y; - } - } - } - } - - if ($this->image_dst_x < 1) { - $this->image_dst_x = 1; - } - if ($this->image_dst_y < 1) { - $this->image_dst_y = 1; - } - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - - if ($gd_version >= 2) { - $res = imagecopyresampled($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y); - } else { - $res = imagecopyresized($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y); - } - - $this->log .= '    resized image object created
'; - $this->log .= '    image_src_x y : ' . $this->image_src_x . ' x ' . $this->image_src_y . '
'; - $this->log .= '    image_dst_x y : ' . $this->image_dst_x . ' x ' . $this->image_dst_y . '
'; - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } else { - $this->image_dst_x = $this->image_src_x; - $this->image_dst_y = $this->image_src_y; - } - - // crop image (and also crops if image_ratio_crop is used) - if ((!empty($this->image_crop) || !is_null($ratio_crop))) { - list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_crop, $this->image_dst_x, $this->image_dst_y, true, true); - // we adjust the cropping if we use image_ratio_crop - if (!is_null($ratio_crop)) { - if (array_key_exists('t', $ratio_crop)) { - $ct += $ratio_crop['t']; - } - if (array_key_exists('r', $ratio_crop)) { - $cr += $ratio_crop['r']; - } - if (array_key_exists('b', $ratio_crop)) { - $cb += $ratio_crop['b']; - } - if (array_key_exists('l', $ratio_crop)) { - $cl += $ratio_crop['l']; - } - } - $this->log .= '- crop image : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '
'; - $this->image_dst_x = $this->image_dst_x - $cl - $cr; - $this->image_dst_y = $this->image_dst_y - $ct - $cb; - if ($this->image_dst_x < 1) { - $this->image_dst_x = 1; - } - if ($this->image_dst_y < 1) { - $this->image_dst_y = 1; - } - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - - // we copy the image into the recieving image - imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_dst_x, $this->image_dst_y); - - // if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent - if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0) { - // use the background color if present - if (!empty($this->image_background_color)) { - list($red, $green, $blue) = $this->getcolors($this->image_background_color); - $fill = imagecolorallocate($tmp, $red, $green, $blue); - } else { - $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); - } - // fills eventual negative margins - if ($ct < 0) { - imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, -$ct - 1, $fill); - } - if ($cr < 0) { - imagefilledrectangle($tmp, $this->image_dst_x + $cr, 0, $this->image_dst_x, $this->image_dst_y, $fill); - } - if ($cb < 0) { - imagefilledrectangle($tmp, 0, $this->image_dst_y + $cb, $this->image_dst_x, $this->image_dst_y, $fill); - } - if ($cl < 0) { - imagefilledrectangle($tmp, 0, 0, -$cl - 1, $this->image_dst_y, $fill); - } - } - - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // flip image - if ($gd_version >= 2 && !empty($this->image_flip)) { - $this->image_flip = strtolower($this->image_flip); - $this->log .= '- flip image : ' . $this->image_flip . '
'; - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - if (strpos($this->image_flip, 'v') !== false) { - imagecopy($tmp, $image_dst, $this->image_dst_x - $x - 1, $y, $x, $y, 1, 1); - } else { - imagecopy($tmp, $image_dst, $x, $this->image_dst_y - $y - 1, $x, $y, 1, 1); - } - } - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // rotate image - if ($gd_version >= 2 && is_numeric($this->image_rotate)) { - if (!in_array($this->image_rotate, [0, 90, 180, 270])) { - $this->image_rotate = 0; - } - if ($this->image_rotate != 0) { - if ($this->image_rotate == 90 || $this->image_rotate == 270) { - $tmp = $this->imagecreatenew($this->image_dst_y, $this->image_dst_x); - } else { - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - } - $this->log .= '- rotate image : ' . $this->image_rotate . '
'; - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - if ($this->image_rotate == 90) { - imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_dst_y - $y - 1, 1, 1); - } else { - if ($this->image_rotate == 180) { - imagecopy($tmp, $image_dst, $x, $y, $this->image_dst_x - $x - 1, $this->image_dst_y - $y - 1, 1, 1); - } else { - if ($this->image_rotate == 270) { - imagecopy($tmp, $image_dst, $y, $x, $this->image_dst_x - $x - 1, $y, 1, 1); - } else { - imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1); - } - } - } - } - } - if ($this->image_rotate == 90 || $this->image_rotate == 270) { - $t = $this->image_dst_y; - $this->image_dst_y = $this->image_dst_x; - $this->image_dst_x = $t; - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - } - - // pixelate image - if ((is_numeric($this->image_pixelate) && $this->image_pixelate > 0)) { - $this->log .= '- pixelate image (' . $this->image_pixelate . 'px)
'; - $filter = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - if ($gd_version >= 2) { - imagecopyresampled($filter, $image_dst, 0, 0, 0, 0, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate), $this->image_dst_x, $this->image_dst_y); - imagecopyresampled($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate)); - } else { - imagecopyresized($filter, $image_dst, 0, 0, 0, 0, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate), $this->image_dst_x, $this->image_dst_y); - imagecopyresized($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate)); - } - imagedestroy($filter); - } - - // unsharp mask - if ($gd_version >= 2 && $this->image_unsharp && is_numeric($this->image_unsharp_amount) && is_numeric($this->image_unsharp_radius) && is_numeric($this->image_unsharp_threshold)) { - // Unsharp Mask for PHP - version 2.1.1 - // Unsharp mask algorithm by Torstein Hønsi 2003-07. - // Used with permission - // Modified to support alpha transparency - if ($this->image_unsharp_amount > 500) { - $this->image_unsharp_amount = 500; - } - $this->image_unsharp_amount = $this->image_unsharp_amount * 0.016; - if ($this->image_unsharp_radius > 50) { - $this->image_unsharp_radius = 50; - } - $this->image_unsharp_radius = $this->image_unsharp_radius * 2; - if ($this->image_unsharp_threshold > 255) { - $this->image_unsharp_threshold = 255; - } - $this->image_unsharp_radius = abs(round($this->image_unsharp_radius)); - if ($this->image_unsharp_radius != 0) { - $this->image_dst_x = imagesx($image_dst); - $this->image_dst_y = imagesy($image_dst); - $canvas = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y, false, true); - $blur = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y, false, true); - if (function_exists('imageconvolution')) { // PHP >= 5.1 - $matrix = [[1, 2, 1], [2, 4, 2], [1, 2, 1]]; - imagecopy($blur, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); - imageconvolution($blur, $matrix, 16, 0); - } else { - for ($i = 0; $i < $this->image_unsharp_radius; $i++) { - imagecopy($blur, $image_dst, 0, 0, 1, 0, $this->image_dst_x - 1, $this->image_dst_y); // left - $this->imagecopymergealpha($blur, $image_dst, 1, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, 50); // right - $this->imagecopymergealpha($blur, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, 50); // center - imagecopy($canvas, $blur, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); - $this->imagecopymergealpha($blur, $canvas, 0, 0, 0, 1, $this->image_dst_x, $this->image_dst_y - 1, 33.33333); // up - $this->imagecopymergealpha($blur, $canvas, 0, 1, 0, 0, $this->image_dst_x, $this->image_dst_y, 25); // down - } - } - $p_new = []; - if ($this->image_unsharp_threshold > 0) { - for ($x = 0; $x < $this->image_dst_x - 1; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - $p_orig = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $p_blur = imagecolorsforindex($blur, imagecolorat($blur, $x, $y)); - $p_new['red'] = (abs($p_orig['red'] - $p_blur['red']) >= $this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig['red'] - $p_blur['red'])) + $p_orig['red'])) : $p_orig['red']; - $p_new['green'] = (abs($p_orig['green'] - $p_blur['green']) >= $this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig['green'] - $p_blur['green'])) + $p_orig['green'])) : $p_orig['green']; - $p_new['blue'] = (abs($p_orig['blue'] - $p_blur['blue']) >= $this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig['blue'] - $p_blur['blue'])) + $p_orig['blue'])) : $p_orig['blue']; - if (($p_orig['red'] != $p_new['red']) || ($p_orig['green'] != $p_new['green']) || ($p_orig['blue'] != $p_new['blue'])) { - $color = imagecolorallocatealpha($image_dst, $p_new['red'], $p_new['green'], $p_new['blue'], $p_orig['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - } - } - } - } else { - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - $p_orig = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $p_blur = imagecolorsforindex($blur, imagecolorat($blur, $x, $y)); - $p_new['red'] = ($this->image_unsharp_amount * ($p_orig['red'] - $p_blur['red'])) + $p_orig['red']; - if ($p_new['red'] > 255) { - $p_new['red'] = 255; - } else { - if ($p_new['red'] < 0) { - $p_new['red'] = 0; - } - } - $p_new['green'] = ($this->image_unsharp_amount * ($p_orig['green'] - $p_blur['green'])) + $p_orig['green']; - if ($p_new['green'] > 255) { - $p_new['green'] = 255; - } else { - if ($p_new['green'] < 0) { - $p_new['green'] = 0; - } - } - $p_new['blue'] = ($this->image_unsharp_amount * ($p_orig['blue'] - $p_blur['blue'])) + $p_orig['blue']; - if ($p_new['blue'] > 255) { - $p_new['blue'] = 255; - } else { - if ($p_new['blue'] < 0) { - $p_new['blue'] = 0; - } - } - $color = imagecolorallocatealpha($image_dst, $p_new['red'], $p_new['green'], $p_new['blue'], $p_orig['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - } - } - } - imagedestroy($canvas); - imagedestroy($blur); - } - } - - // add color overlay - if ($gd_version >= 2 && (is_numeric($this->image_overlay_opacity) && $this->image_overlay_opacity > 0 && !empty($this->image_overlay_color))) { - $this->log .= '- apply color overlay
'; - list($red, $green, $blue) = $this->getcolors($this->image_overlay_color); - $filter = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y); - $color = imagecolorallocate($filter, $red, $green, $blue); - imagefilledrectangle($filter, 0, 0, $this->image_dst_x, $this->image_dst_y, $color); - $this->imagecopymergealpha($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_overlay_opacity); - imagedestroy($filter); - } - - // add brightness, contrast and tint, turns to greyscale and inverts colors - if ($gd_version >= 2 && ($this->image_negative || $this->image_greyscale || is_numeric($this->image_threshold) || is_numeric($this->image_brightness) || is_numeric($this->image_contrast) || !empty($this->image_tint_color))) { - $this->log .= '- apply tint, light, contrast correction, negative, greyscale and threshold
'; - if (!empty($this->image_tint_color)) { - list($tint_red, $tint_green, $tint_blue) = $this->getcolors($this->image_tint_color); - } - //imagealphablending($image_dst, true); - for ($y = 0; $y < $this->image_dst_y; $y++) { - for ($x = 0; $x < $this->image_dst_x; $x++) { - if ($this->image_greyscale) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $r = $g = $b = round((0.2125 * $pixel['red']) + (0.7154 * $pixel['green']) + (0.0721 * $pixel['blue'])); - $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - unset($color); - unset($pixel); - } - if (is_numeric($this->image_threshold)) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $c = (round($pixel['red'] + $pixel['green'] + $pixel['blue']) / 3) - 127; - $r = $g = $b = ($c > $this->image_threshold ? 255 : 0); - $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - unset($color); - unset($pixel); - } - if (is_numeric($this->image_brightness)) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $r = max(min(round($pixel['red'] + (($this->image_brightness * 2))), 255), 0); - $g = max(min(round($pixel['green'] + (($this->image_brightness * 2))), 255), 0); - $b = max(min(round($pixel['blue'] + (($this->image_brightness * 2))), 255), 0); - $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - unset($color); - unset($pixel); - } - if (is_numeric($this->image_contrast)) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $r = max(min(round(($this->image_contrast + 128) * $pixel['red'] / 128), 255), 0); - $g = max(min(round(($this->image_contrast + 128) * $pixel['green'] / 128), 255), 0); - $b = max(min(round(($this->image_contrast + 128) * $pixel['blue'] / 128), 255), 0); - $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - unset($color); - unset($pixel); - } - if (!empty($this->image_tint_color)) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $r = min(round($tint_red * $pixel['red'] / 169), 255); - $g = min(round($tint_green * $pixel['green'] / 169), 255); - $b = min(round($tint_blue * $pixel['blue'] / 169), 255); - $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - unset($color); - unset($pixel); - } - if (!empty($this->image_negative)) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $r = round(255 - $pixel['red']); - $g = round(255 - $pixel['green']); - $b = round(255 - $pixel['blue']); - $color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); - imagesetpixel($image_dst, $x, $y, $color); - unset($color); - unset($pixel); - } - } - } - } - - // adds a border - if ($gd_version >= 2 && !empty($this->image_border)) { - list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_border, $this->image_dst_x, $this->image_dst_y, true, false); - $this->log .= '- add border : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '
'; - $this->image_dst_x = $this->image_dst_x + $cl + $cr; - $this->image_dst_y = $this->image_dst_y + $ct + $cb; - if (!empty($this->image_border_color)) { - list($red, $green, $blue) = $this->getcolors($this->image_border_color); - } - $opacity = (is_numeric($this->image_border_opacity) ? (int)(127 - $this->image_border_opacity / 100 * 127) : 0); - // we now create an image, that we fill with the border color - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - $background = imagecolorallocatealpha($tmp, $red, $green, $blue, $opacity); - imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, $this->image_dst_y, $background); - // we then copy the source image into the new image, without merging so that only the border is actually kept - imagecopy($tmp, $image_dst, $cl, $ct, 0, 0, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct); - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // adds a fading-to-transparent border - if ($gd_version >= 2 && !empty($this->image_border_transparent)) { - list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_border_transparent, $this->image_dst_x, $this->image_dst_y, true, false); - $this->log .= '- add transparent border : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '
'; - // we now create an image, that we fill with the border color - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - // we then copy the source image into the new image, without the borders - imagecopy($tmp, $image_dst, $cl, $ct, $cl, $ct, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct); - // we now add the top border - $opacity = 100; - for ($y = $ct - 1; $y >= 0; $y--) { - $il = (int)($ct > 0 ? ($cl * ($y / $ct)) : 0); - $ir = (int)($ct > 0 ? ($cr * ($y / $ct)) : 0); - for ($x = $il; $x < $this->image_dst_x - $ir; $x++) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; - if ($alpha > 0) { - if ($alpha > 1) { - $alpha = 1; - } - $color = imagecolorallocatealpha($tmp, $pixel['red'], $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); - imagesetpixel($tmp, $x, $y, $color); - } - } - if ($opacity > 0) { - $opacity = $opacity - (100 / $ct); - } - } - // we now add the right border - $opacity = 100; - for ($x = $this->image_dst_x - $cr; $x < $this->image_dst_x; $x++) { - $it = (int)($cr > 0 ? ($ct * (($this->image_dst_x - $x - 1) / $cr)) : 0); - $ib = (int)($cr > 0 ? ($cb * (($this->image_dst_x - $x - 1) / $cr)) : 0); - for ($y = $it; $y < $this->image_dst_y - $ib; $y++) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; - if ($alpha > 0) { - if ($alpha > 1) { - $alpha = 1; - } - $color = imagecolorallocatealpha($tmp, $pixel['red'], $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); - imagesetpixel($tmp, $x, $y, $color); - } - } - if ($opacity > 0) { - $opacity = $opacity - (100 / $cr); - } - } - // we now add the bottom border - $opacity = 100; - for ($y = $this->image_dst_y - $cb; $y < $this->image_dst_y; $y++) { - $il = (int)($cb > 0 ? ($cl * (($this->image_dst_y - $y - 1) / $cb)) : 0); - $ir = (int)($cb > 0 ? ($cr * (($this->image_dst_y - $y - 1) / $cb)) : 0); - for ($x = $il; $x < $this->image_dst_x - $ir; $x++) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; - if ($alpha > 0) { - if ($alpha > 1) { - $alpha = 1; - } - $color = imagecolorallocatealpha($tmp, $pixel['red'], $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); - imagesetpixel($tmp, $x, $y, $color); - } - } - if ($opacity > 0) { - $opacity = $opacity - (100 / $cb); - } - } - // we now add the left border - $opacity = 100; - for ($x = $cl - 1; $x >= 0; $x--) { - $it = (int)($cl > 0 ? ($ct * ($x / $cl)) : 0); - $ib = (int)($cl > 0 ? ($cb * ($x / $cl)) : 0); - for ($y = $it; $y < $this->image_dst_y - $ib; $y++) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; - if ($alpha > 0) { - if ($alpha > 1) { - $alpha = 1; - } - $color = imagecolorallocatealpha($tmp, $pixel['red'], $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); - imagesetpixel($tmp, $x, $y, $color); - } - } - if ($opacity > 0) { - $opacity = $opacity - (100 / $cl); - } - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // add frame border - if ($gd_version >= 2 && is_numeric($this->image_frame)) { - if (is_array($this->image_frame_colors)) { - $vars = $this->image_frame_colors; - $this->log .= '- add frame : ' . implode(' ', $this->image_frame_colors) . '
'; - } else { - $this->log .= '- add frame : ' . $this->image_frame_colors . '
'; - $vars = explode(' ', $this->image_frame_colors); - } - $nb = sizeof($vars); - $this->image_dst_x = $this->image_dst_x + ($nb * 2); - $this->image_dst_y = $this->image_dst_y + ($nb * 2); - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - imagecopy($tmp, $image_dst, $nb, $nb, 0, 0, $this->image_dst_x - ($nb * 2), $this->image_dst_y - ($nb * 2)); - $opacity = (is_numeric($this->image_frame_opacity) ? (int)(127 - $this->image_frame_opacity / 100 * 127) : 0); - for ($i = 0; $i < $nb; $i++) { - list($red, $green, $blue) = $this->getcolors($vars[$i]); - $c = imagecolorallocatealpha($tmp, $red, $green, $blue, $opacity); - if ($this->image_frame == 1) { - imageline($tmp, $i, $i, $this->image_dst_x - $i - 1, $i, $c); - imageline($tmp, $this->image_dst_x - $i - 1, $this->image_dst_y - $i - 1, $this->image_dst_x - $i - 1, $i, $c); - imageline($tmp, $this->image_dst_x - $i - 1, $this->image_dst_y - $i - 1, $i, $this->image_dst_y - $i - 1, $c); - imageline($tmp, $i, $i, $i, $this->image_dst_y - $i - 1, $c); - } else { - imageline($tmp, $i, $i, $this->image_dst_x - $i - 1, $i, $c); - imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $this->image_dst_x - $nb + $i, $nb - $i, $c); - imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $nb - $i, $this->image_dst_y - $nb + $i, $c); - imageline($tmp, $i, $i, $i, $this->image_dst_y - $i - 1, $c); - } - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // add bevel border - if ($gd_version >= 2 && $this->image_bevel > 0) { - if (empty($this->image_bevel_color1)) { - $this->image_bevel_color1 = '#FFFFFF'; - } - if (empty($this->image_bevel_color2)) { - $this->image_bevel_color2 = '#000000'; - } - list($red1, $green1, $blue1) = $this->getcolors($this->image_bevel_color1); - list($red2, $green2, $blue2) = $this->getcolors($this->image_bevel_color2); - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); - imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); - imagealphablending($tmp, true); - for ($i = 0; $i < $this->image_bevel; $i++) { - $alpha = round(($i / $this->image_bevel) * 127); - $c1 = imagecolorallocatealpha($tmp, $red1, $green1, $blue1, $alpha); - $c2 = imagecolorallocatealpha($tmp, $red2, $green2, $blue2, $alpha); - imageline($tmp, $i, $i, $this->image_dst_x - $i - 1, $i, $c1); - imageline($tmp, $this->image_dst_x - $i - 1, $this->image_dst_y - $i, $this->image_dst_x - $i - 1, $i, $c2); - imageline($tmp, $this->image_dst_x - $i - 1, $this->image_dst_y - $i - 1, $i, $this->image_dst_y - $i - 1, $c2); - imageline($tmp, $i, $i, $i, $this->image_dst_y - $i - 1, $c1); - } - // we transfert tmp into image_dst - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // add watermark image - if ($this->image_watermark != '' && file_exists($this->image_watermark)) { - $this->log .= '- add watermark
'; - $this->image_watermark_position = strtolower($this->image_watermark_position); - $watermark_info = getimagesize($this->image_watermark); - $watermark_type = (array_key_exists(2, $watermark_info) ? $watermark_info[2] : null); // 1 = GIF, 2 = JPG, 3 = PNG - $watermark_checked = false; - if ($watermark_type == IMAGETYPE_GIF) { - if (!function_exists('imagecreatefromgif')) { - $this->error = $this->translate('watermark_no_create_support', ['GIF']); - } else { - $filter = @imagecreatefromgif($this->image_watermark); - if (!$filter) { - $this->error = $this->translate('watermark_create_error', ['GIF']); - } else { - $this->log .= '    watermark source image is GIF
'; - $watermark_checked = true; - } - } - } else { - if ($watermark_type == IMAGETYPE_JPEG) { - if (!function_exists('imagecreatefromjpeg')) { - $this->error = $this->translate('watermark_no_create_support', ['JPEG']); - } else { - $filter = @imagecreatefromjpeg($this->image_watermark); - if (!$filter) { - $this->error = $this->translate('watermark_create_error', ['JPEG']); - } else { - $this->log .= '    watermark source image is JPEG
'; - $watermark_checked = true; - } - } - } else { - if ($watermark_type == IMAGETYPE_PNG) { - if (!function_exists('imagecreatefrompng')) { - $this->error = $this->translate('watermark_no_create_support', ['PNG']); - } else { - $filter = @imagecreatefrompng($this->image_watermark); - if (!$filter) { - $this->error = $this->translate('watermark_create_error', ['PNG']); - } else { - $this->log .= '    watermark source image is PNG
'; - $watermark_checked = true; - } - } - } else { - if ($watermark_type == IMAGETYPE_BMP) { - if (!method_exists($this, 'imagecreatefrombmp')) { - $this->error = $this->translate('watermark_no_create_support', ['BMP']); - } else { - $filter = @$this->imagecreatefrombmp($this->image_watermark); - if (!$filter) { - $this->error = $this->translate('watermark_create_error', ['BMP']); - } else { - $this->log .= '    watermark source image is BMP
'; - $watermark_checked = true; - } - } - } else { - $this->error = $this->translate('watermark_invalid'); - } - } - } - } - if ($watermark_checked) { - $watermark_dst_width = $watermark_src_width = imagesx($filter); - $watermark_dst_height = $watermark_src_height = imagesy($filter); - - // if watermark is too large/tall, resize it first - if ((!$this->image_watermark_no_zoom_out && ($watermark_dst_width > $this->image_dst_x || $watermark_dst_height > $this->image_dst_y)) - || (!$this->image_watermark_no_zoom_in && $watermark_dst_width < $this->image_dst_x && $watermark_dst_height < $this->image_dst_y)) { - $canvas_width = $this->image_dst_x - abs($this->image_watermark_x); - $canvas_height = $this->image_dst_y - abs($this->image_watermark_y); - if (($watermark_src_width / $canvas_width) > ($watermark_src_height / $canvas_height)) { - $watermark_dst_width = $canvas_width; - $watermark_dst_height = intval($watermark_src_height * ($canvas_width / $watermark_src_width)); - } else { - $watermark_dst_height = $canvas_height; - $watermark_dst_width = intval($watermark_src_width * ($canvas_height / $watermark_src_height)); - } - $this->log .= '    watermark resized from ' . $watermark_src_width . 'x' . $watermark_src_height . ' to ' . $watermark_dst_width . 'x' . $watermark_dst_height . '
'; - } - // determine watermark position - $watermark_x = 0; - $watermark_y = 0; - if (is_numeric($this->image_watermark_x)) { - if ($this->image_watermark_x < 0) { - $watermark_x = $this->image_dst_x - $watermark_dst_width + $this->image_watermark_x; - } else { - $watermark_x = $this->image_watermark_x; - } - } else { - if (strpos($this->image_watermark_position, 'r') !== false) { - $watermark_x = $this->image_dst_x - $watermark_dst_width; - } else { - if (strpos($this->image_watermark_position, 'l') !== false) { - $watermark_x = 0; - } else { - $watermark_x = ($this->image_dst_x - $watermark_dst_width) / 2; - } - } - } - if (is_numeric($this->image_watermark_y)) { - if ($this->image_watermark_y < 0) { - $watermark_y = $this->image_dst_y - $watermark_dst_height + $this->image_watermark_y; - } else { - $watermark_y = $this->image_watermark_y; - } - } else { - if (strpos($this->image_watermark_position, 'b') !== false) { - $watermark_y = $this->image_dst_y - $watermark_dst_height; - } else { - if (strpos($this->image_watermark_position, 't') !== false) { - $watermark_y = 0; - } else { - $watermark_y = ($this->image_dst_y - $watermark_dst_height) / 2; - } - } - } - imagealphablending($image_dst, true); - imagecopyresampled($image_dst, $filter, $watermark_x, $watermark_y, 0, 0, $watermark_dst_width, $watermark_dst_height, $watermark_src_width, $watermark_src_height); - } else { - $this->error = $this->translate('watermark_invalid'); - } - } - - // add text - if (!empty($this->image_text)) { - $this->log .= '- add text
'; - - // calculate sizes in human readable format - $src_size = $this->file_src_size / 1024; - $src_size_mb = number_format($src_size / 1024, 1, ".", " "); - $src_size_kb = number_format($src_size, 1, ".", " "); - $src_size_human = ($src_size > 1024 ? $src_size_mb . " MB" : $src_size_kb . " kb"); - - $this->image_text = str_replace( - [ - '[src_name]', - '[src_name_body]', - '[src_name_ext]', - '[src_pathname]', - '[src_mime]', - '[src_size]', - '[src_size_kb]', - '[src_size_mb]', - '[src_size_human]', - '[src_x]', - '[src_y]', - '[src_pixels]', - '[src_type]', - '[src_bits]', - '[dst_path]', - '[dst_name_body]', - '[dst_name_ext]', - '[dst_name]', - '[dst_pathname]', - '[dst_x]', - '[dst_y]', - '[date]', - '[time]', - '[host]', - '[server]', - '[ip]', - '[gd_version]', - ], - [ - $this->file_src_name, - $this->file_src_name_body, - $this->file_src_name_ext, - $this->file_src_pathname, - $this->file_src_mime, - $this->file_src_size, - $src_size_kb, - $src_size_mb, - $src_size_human, - $this->image_src_x, - $this->image_src_y, - $this->image_src_pixels, - $this->image_src_type, - $this->image_src_bits, - $this->file_dst_path, - $this->file_dst_name_body, - $this->file_dst_name_ext, - $this->file_dst_name, - $this->file_dst_pathname, - $this->image_dst_x, - $this->image_dst_y, - date('Y-m-d'), - date('H:i:s'), - (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'n/a'), - (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'n/a'), - (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'n/a'), - $this->gdversion(true), - ], - $this->image_text); - - if (!is_numeric($this->image_text_padding)) { - $this->image_text_padding = 0; - } - if (!is_numeric($this->image_text_line_spacing)) { - $this->image_text_line_spacing = 0; - } - if (!is_numeric($this->image_text_padding_x)) { - $this->image_text_padding_x = $this->image_text_padding; - } - if (!is_numeric($this->image_text_padding_y)) { - $this->image_text_padding_y = $this->image_text_padding; - } - $this->image_text_position = strtolower($this->image_text_position); - $this->image_text_direction = strtolower($this->image_text_direction); - $this->image_text_alignment = strtolower($this->image_text_alignment); - - // if the font is a string, we assume that we might want to load a font - if (!is_numeric($this->image_text_font) && strlen($this->image_text_font) > 4 && substr(strtolower($this->image_text_font), -4) == '.gdf') { - $this->log .= '    try to load font ' . $this->image_text_font . '... '; - if ($this->image_text_font = @imageloadfont($this->image_text_font)) { - $this->log .= 'success
'; - } else { - $this->log .= 'error
'; - $this->image_text_font = 5; - } - } - - $text = explode("\n", $this->image_text); - $char_width = imagefontwidth($this->image_text_font); - $char_height = imagefontheight($this->image_text_font); - $text_height = 0; - $text_width = 0; - $line_height = 0; - $line_width = 0; - - foreach ($text as $k => $v) { - if ($this->image_text_direction == 'v') { - $h = ($char_width * strlen($v)); - if ($h > $text_height) { - $text_height = $h; - } - $line_width = $char_height; - $text_width += $line_width + ($k < (sizeof($text) - 1) ? $this->image_text_line_spacing : 0); - } else { - $w = ($char_width * strlen($v)); - if ($w > $text_width) { - $text_width = $w; - } - $line_height = $char_height; - $text_height += $line_height + ($k < (sizeof($text) - 1) ? $this->image_text_line_spacing : 0); - } - } - $text_width += (2 * $this->image_text_padding_x); - $text_height += (2 * $this->image_text_padding_y); - $text_x = 0; - $text_y = 0; - if (is_numeric($this->image_text_x)) { - if ($this->image_text_x < 0) { - $text_x = $this->image_dst_x - $text_width + $this->image_text_x; - } else { - $text_x = $this->image_text_x; - } - } else { - if (strpos($this->image_text_position, 'r') !== false) { - $text_x = $this->image_dst_x - $text_width; - } else { - if (strpos($this->image_text_position, 'l') !== false) { - $text_x = 0; - } else { - $text_x = ($this->image_dst_x - $text_width) / 2; - } - } - } - if (is_numeric($this->image_text_y)) { - if ($this->image_text_y < 0) { - $text_y = $this->image_dst_y - $text_height + $this->image_text_y; - } else { - $text_y = $this->image_text_y; - } - } else { - if (strpos($this->image_text_position, 'b') !== false) { - $text_y = $this->image_dst_y - $text_height; - } else { - if (strpos($this->image_text_position, 't') !== false) { - $text_y = 0; - } else { - $text_y = ($this->image_dst_y - $text_height) / 2; - } - } - } - - // add a background, maybe transparent - if (!empty($this->image_text_background)) { - list($red, $green, $blue) = $this->getcolors($this->image_text_background); - if ($gd_version >= 2 && (is_numeric($this->image_text_background_opacity)) && $this->image_text_background_opacity >= 0 && $this->image_text_background_opacity <= 100) { - $filter = imagecreatetruecolor($text_width, $text_height); - $background_color = imagecolorallocate($filter, $red, $green, $blue); - imagefilledrectangle($filter, 0, 0, $text_width, $text_height, $background_color); - $this->imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $text_width, $text_height, $this->image_text_background_opacity); - imagedestroy($filter); - } else { - $background_color = imagecolorallocate($image_dst, $red, $green, $blue); - imagefilledrectangle($image_dst, $text_x, $text_y, $text_x + $text_width, $text_y + $text_height, $background_color); - } - } - - $text_x += $this->image_text_padding_x; - $text_y += $this->image_text_padding_y; - $t_width = $text_width - (2 * $this->image_text_padding_x); - $t_height = $text_height - (2 * $this->image_text_padding_y); - list($red, $green, $blue) = $this->getcolors($this->image_text_color); - - // add the text, maybe transparent - if ($gd_version >= 2 && (is_numeric($this->image_text_opacity)) && $this->image_text_opacity >= 0 && $this->image_text_opacity <= 100) { - if ($t_width < 0) { - $t_width = 0; - } - if ($t_height < 0) { - $t_height = 0; - } - $filter = $this->imagecreatenew($t_width, $t_height, false, true); - $text_color = imagecolorallocate($filter, $red, $green, $blue); - - foreach ($text as $k => $v) { - if ($this->image_text_direction == 'v') { - imagestringup($filter, - $this->image_text_font, - $k * ($line_width + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), - $text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment == 'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), - $v, - $text_color); - } else { - imagestring($filter, - $this->image_text_font, - ($this->image_text_alignment == 'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), - $k * ($line_height + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), - $v, - $text_color); - } - } - $this->imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $t_width, $t_height, $this->image_text_opacity); - imagedestroy($filter); - } else { - $text_color = imageColorAllocate($image_dst, $red, $green, $blue); - foreach ($text as $k => $v) { - if ($this->image_text_direction == 'v') { - imagestringup($image_dst, - $this->image_text_font, - $text_x + $k * ($line_width + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), - $text_y + $text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment == 'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), - $v, - $text_color); - } else { - imagestring($image_dst, - $this->image_text_font, - $text_x + ($this->image_text_alignment == 'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), - $text_y + $k * ($line_height + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), - $v, - $text_color); - } - } - } - } - - // add a reflection - if ($this->image_reflection_height) { - $this->log .= '- add reflection : ' . $this->image_reflection_height . '
'; - // we decode image_reflection_height, which can be a integer, a string in pixels or percentage - $image_reflection_height = $this->image_reflection_height; - if (strpos($image_reflection_height, '%') > 0) { - $image_reflection_height = $this->image_dst_y * (str_replace('%', '', $image_reflection_height / 100)); - } - if (strpos($image_reflection_height, 'px') > 0) { - $image_reflection_height = str_replace('px', '', $image_reflection_height); - } - $image_reflection_height = (int)$image_reflection_height; - if ($image_reflection_height > $this->image_dst_y) { - $image_reflection_height = $this->image_dst_y; - } - if (empty($this->image_reflection_opacity)) { - $this->image_reflection_opacity = 60; - } - // create the new destination image - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y + $image_reflection_height + $this->image_reflection_space, true); - $transparency = $this->image_reflection_opacity; - - // copy the original image - imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0)); - - // we have to make sure the extra bit is the right color, or transparent - if ($image_reflection_height + $this->image_reflection_space > 0) { - // use the background color if present - if (!empty($this->image_background_color)) { - list($red, $green, $blue) = $this->getcolors($this->image_background_color); - $fill = imagecolorallocate($tmp, $red, $green, $blue); - } else { - $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); - } - // fill in from the edge of the extra bit - imagefill($tmp, round($this->image_dst_x / 2), $this->image_dst_y + $image_reflection_height + $this->image_reflection_space - 1, $fill); - } - - // copy the reflection - for ($y = 0; $y < $image_reflection_height; $y++) { - for ($x = 0; $x < $this->image_dst_x; $x++) { - $pixel_b = imagecolorsforindex($tmp, imagecolorat($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space)); - $pixel_o = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $this->image_dst_y - $y - 1 + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0))); - $alpha_o = 1 - ($pixel_o['alpha'] / 127); - $alpha_b = 1 - ($pixel_b['alpha'] / 127); - $opacity = $alpha_o * $transparency / 100; - if ($opacity > 0) { - $red = round((($pixel_o['red'] * $opacity) + ($pixel_b['red']) * $alpha_b) / ($alpha_b + $opacity)); - $green = round((($pixel_o['green'] * $opacity) + ($pixel_b['green']) * $alpha_b) / ($alpha_b + $opacity)); - $blue = round((($pixel_o['blue'] * $opacity) + ($pixel_b['blue']) * $alpha_b) / ($alpha_b + $opacity)); - $alpha = ($opacity + $alpha_b); - if ($alpha > 1) { - $alpha = 1; - } - $alpha = round((1 - $alpha) * 127); - $color = imagecolorallocatealpha($tmp, $red, $green, $blue, $alpha); - imagesetpixel($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space, $color); - } - } - if ($transparency > 0) { - $transparency = $transparency - ($this->image_reflection_opacity / $image_reflection_height); - } - } - - // copy the resulting image into the destination image - $this->image_dst_y = $this->image_dst_y + $image_reflection_height + $this->image_reflection_space; - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // change opacity - if ($gd_version >= 2 && is_numeric($this->image_opacity) && $this->image_opacity < 100) { - $this->log .= '- change opacity
'; - // create the new destination image - $tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y, true); - for ($y = 0; $y < $this->image_dst_y; $y++) { - for ($x = 0; $x < $this->image_dst_x; $x++) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $alpha = $pixel['alpha'] + round((127 - $pixel['alpha']) * (100 - $this->image_opacity) / 100); - if ($alpha > 127) { - $alpha = 127; - } - if ($alpha > 0) { - $color = imagecolorallocatealpha($tmp, $pixel['red'], $pixel['green'], $pixel['blue'], $alpha); - imagesetpixel($tmp, $x, $y, $color); - } - } - } - // copy the resulting image into the destination image - $image_dst = $this->imagetransfer($tmp, $image_dst); - } - - // reduce the JPEG image to a set desired size - if (is_numeric($this->jpeg_size) && $this->jpeg_size > 0 && ($this->image_convert == 'jpeg' || $this->image_convert == 'jpg')) { - // inspired by: JPEGReducer class version 1, 25 November 2004, Author: Huda M ElMatsani, justhuda at netscape dot net - $this->log .= '- JPEG desired file size : ' . $this->jpeg_size . '
'; - // calculate size of each image. 75%, 50%, and 25% quality - ob_start(); - imagejpeg($image_dst, null, 75); - $buffer = ob_get_contents(); - ob_end_clean(); - $size75 = strlen($buffer); - ob_start(); - imagejpeg($image_dst, null, 50); - $buffer = ob_get_contents(); - ob_end_clean(); - $size50 = strlen($buffer); - ob_start(); - imagejpeg($image_dst, null, 25); - $buffer = ob_get_contents(); - ob_end_clean(); - $size25 = strlen($buffer); - - // make sure we won't divide by 0 - if ($size50 == $size25) { - $size50++; - } - if ($size75 == $size50 || $size75 == $size25) { - $size75++; - } - - // calculate gradient of size reduction by quality - $mgrad1 = 25 / ($size50 - $size25); - $mgrad2 = 25 / ($size75 - $size50); - $mgrad3 = 50 / ($size75 - $size25); - $mgrad = ($mgrad1 + $mgrad2 + $mgrad3) / 3; - // result of approx. quality factor for expected size - $q_factor = round($mgrad * ($this->jpeg_size - $size50) + 50); - - if ($q_factor < 1) { - $this->jpeg_quality = 1; - } else { - if ($q_factor > 100) { - $this->jpeg_quality = 100; - } else { - $this->jpeg_quality = $q_factor; - } - } - $this->log .= '    JPEG quality factor set to ' . $this->jpeg_quality . '
'; - } - - // converts image from true color, and fix transparency if needed - $this->log .= '- converting...
'; - $this->image_dst_type = $this->image_convert; - switch ($this->image_convert) { - case 'gif': - // if the image is true color, we convert it to a palette - if (imageistruecolor($image_dst)) { - $this->log .= '    true color to palette
'; - // creates a black and white mask - $mask = [[]]; - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $mask[$x][$y] = $pixel['alpha']; - } - } - list($red, $green, $blue) = $this->getcolors($this->image_default_color); - // first, we merge the image with the background color, so we know which colors we will have - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - if ($mask[$x][$y] > 0) { - // we have some transparency. we combine the color with the default color - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - $alpha = ($mask[$x][$y] / 127); - $pixel['red'] = round(($pixel['red'] * (1 - $alpha) + $red * ($alpha))); - $pixel['green'] = round(($pixel['green'] * (1 - $alpha) + $green * ($alpha))); - $pixel['blue'] = round(($pixel['blue'] * (1 - $alpha) + $blue * ($alpha))); - $color = imagecolorallocate($image_dst, $pixel['red'], $pixel['green'], $pixel['blue']); - imagesetpixel($image_dst, $x, $y, $color); - } - } - } - // transforms the true color image into palette, with its merged default color - if (empty($this->image_background_color)) { - imagetruecolortopalette($image_dst, true, 255); - $transparency = imagecolorallocate($image_dst, 254, 1, 253); - imagecolortransparent($image_dst, $transparency); - // make the transparent areas transparent - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - // we test wether we have enough opacity to justify keeping the color - if ($mask[$x][$y] > 120) { - imagesetpixel($image_dst, $x, $y, $transparency); - } - } - } - } - unset($mask); - } - break; - case 'jpg': - case 'bmp': - // if the image doesn't support any transparency, then we merge it with the default color - $this->log .= '    fills in transparency with default color
'; - list($red, $green, $blue) = $this->getcolors($this->image_default_color); - $transparency = imagecolorallocate($image_dst, $red, $green, $blue); - // make the transaparent areas transparent - for ($x = 0; $x < $this->image_dst_x; $x++) { - for ($y = 0; $y < $this->image_dst_y; $y++) { - // we test wether we have some transparency, in which case we will merge the colors - if (imageistruecolor($image_dst)) { - $rgba = imagecolorat($image_dst, $x, $y); - $pixel = [ - 'red' => ($rgba >> 16) & 0xFF, - 'green' => ($rgba >> 8) & 0xFF, - 'blue' => $rgba & 0xFF, - 'alpha' => ($rgba & 0x7F000000) >> 24, - ]; - } else { - $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); - } - if ($pixel['alpha'] == 127) { - // we have full transparency. we make the pixel transparent - imagesetpixel($image_dst, $x, $y, $transparency); - } else { - if ($pixel['alpha'] > 0) { - // we have some transparency. we combine the color with the default color - $alpha = ($pixel['alpha'] / 127); - $pixel['red'] = round(($pixel['red'] * (1 - $alpha) + $red * ($alpha))); - $pixel['green'] = round(($pixel['green'] * (1 - $alpha) + $green * ($alpha))); - $pixel['blue'] = round(($pixel['blue'] * (1 - $alpha) + $blue * ($alpha))); - $color = imagecolorclosest($image_dst, $pixel['red'], $pixel['green'], $pixel['blue']); - imagesetpixel($image_dst, $x, $y, $color); - } - } - } - } - - break; - default: - break; - } - - // interlace options - if ($this->image_interlace) { - imageinterlace($image_dst, true); - } - - // outputs image - $this->log .= '- saving image...
'; - switch ($this->image_convert) { - case 'jpeg': - case 'jpg': - if (!$return_mode) { - $result = @imagejpeg($image_dst, $this->file_dst_pathname, $this->jpeg_quality); - } else { - ob_start(); - $result = @imagejpeg($image_dst, null, $this->jpeg_quality); - $return_content = ob_get_contents(); - ob_end_clean(); - } - if (!$result) { - $this->processed = false; - $this->error = $this->translate('file_create', ['JPEG']); - } else { - $this->log .= '    JPEG image created
'; - } - break; - case 'png': - imagealphablending($image_dst, false); - imagesavealpha($image_dst, true); - if (!$return_mode) { - if (is_numeric($this->png_compression) && version_compare(PHP_VERSION, '5.1.2') >= 0) { - $result = @imagepng($image_dst, $this->file_dst_pathname, $this->png_compression); - } else { - $result = @imagepng($image_dst, $this->file_dst_pathname); - } - } else { - ob_start(); - if (is_numeric($this->png_compression) && version_compare(PHP_VERSION, '5.1.2') >= 0) { - $result = @imagepng($image_dst, null, $this->png_compression); - } else { - $result = @imagepng($image_dst); - } - $return_content = ob_get_contents(); - ob_end_clean(); - } - if (!$result) { - $this->processed = false; - $this->error = $this->translate('file_create', ['PNG']); - } else { - $this->log .= '    PNG image created
'; - } - break; - case 'gif': - if (!$return_mode) { - $result = @imagegif($image_dst, $this->file_dst_pathname); - } else { - ob_start(); - $result = @imagegif($image_dst); - $return_content = ob_get_contents(); - ob_end_clean(); - } - if (!$result) { - $this->processed = false; - $this->error = $this->translate('file_create', ['GIF']); - } else { - $this->log .= '    GIF image created
'; - } - break; - case 'bmp': - if (!$return_mode) { - $result = $this->imagebmp($image_dst, $this->file_dst_pathname); - } else { - ob_start(); - $result = $this->imagebmp($image_dst); - $return_content = ob_get_contents(); - ob_end_clean(); - } - if (!$result) { - $this->processed = false; - $this->error = $this->translate('file_create', ['BMP']); - } else { - $this->log .= '    BMP image created
'; - } - break; - - default: - $this->processed = false; - $this->error = $this->translate('no_conversion_type'); - } - if ($this->processed) { - if (is_resource($image_src)) { - imagedestroy($image_src); - } - if (is_resource($image_dst)) { - imagedestroy($image_dst); - } - $this->log .= '    image objects destroyed
'; - } - } - } else { - $this->log .= '- no image processing wanted
'; - - if (!$return_mode) { - // copy the file to its final destination. we don't use move_uploaded_file here - // if we happen to have open_basedir restrictions, it is a temp file that we copy, not the original uploaded file - if (!copy($this->file_src_pathname, $this->file_dst_pathname)) { - $this->processed = false; - $this->error = $this->translate('copy_failed'); - } - } else { - // returns the file, so that its content can be received by the caller - $return_content = @file_get_contents($this->file_src_pathname); - if ($return_content === false) { - $this->processed = false; - $this->error = $this->translate('reading_failed'); - } - } - } - } - - if ($this->processed) { - $this->log .= '- process OK
'; - } else { - $this->log .= '- error: ' . $this->error . '
'; - } - - // we reinit all the vars - $this->init(); - - // we may return the image content - if ($return_mode) { - return $return_content; - } - } - - /** - * Deletes the uploaded file from its temporary location - * - * When PHP uploads a file, it stores it in a temporary location. - * When you {@link process} the file, you actually copy the resulting file to the given location, it doesn't alter - * the original file. Once you have processed the file as many times as you wanted, you can delete the uploaded - * file. If there is open_basedir restrictions, the uploaded file is in fact a temporary file - * - * You might want not to use this function if you work on local files, as it will delete the source file - * - * @access public - */ - function clean() - { - $this->log .= 'cleanup
'; - $this->log .= '- delete temp file ' . $this->file_src_pathname . '
'; - @unlink($this->file_src_pathname); - } - - /** - * Opens a BMP image - * - * This function has been written by DHKold, and is used with permission of the author - * - * @access public - * @param $filename - * @return bool|resource - */ - function imagecreatefrombmp($filename) - { - if (!$f1 = fopen($filename, "rb")) { - return false; - } - - $file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14)); - if ($file['file_type'] != 19778) { - return false; - } - - $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']; - } - $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; - } - - $palette = []; - if ($bmp['colors'] < 16777216) { - $palette = unpack('V' . $bmp['colors'], fread($f1, $bmp['colors'] * 4)); - } - - $im = 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($im, $P, 3).$vide); - else if ($bmp['bits_per_pixel'] == 16) { - $color = unpack("n", substr($im, $P, 2)); - $color[1] = $palette[$color[1] + 1]; - } else if ($bmp['bits_per_pixel'] == 8) { - $color = unpack("n", $vide.substr($im, $P, 1)); - $color[1] = $palette[$color[1] + 1]; - } else if ($bmp['bits_per_pixel'] == 4) { - $color = unpack("n", $vide.substr($im, 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]; - } else if ($bmp['bits_per_pixel'] == 1) { - $color = unpack("n", $vide.substr($im, floor($P), 1)); - if (($P * 8) % 8 == 0) $color[1] = $color[1] >> 7; - else if (($P * 8) % 8 == 1) $color[1] = ($color[1] & 0x40) >> 6; - else if (($P * 8) % 8 == 2) $color[1] = ($color[1] & 0x20) >> 5; - else if (($P * 8) % 8 == 3) $color[1] = ($color[1] & 0x10) >> 4; - else if (($P * 8) % 8 == 4) $color[1] = ($color[1] & 0x8) >> 3; - else if (($P * 8) % 8 == 5) $color[1] = ($color[1] & 0x4) >> 2; - else if (($P * 8) % 8 == 6) $color[1] = ($color[1] & 0x2) >> 1; - else if (($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']; - } - $Y--; - $P += $bmp['decal']; - } - fclose($f1); - - return $res; - } - - /** - * Saves a BMP image - * - * This function has been published on the PHP website, and can be used freely - * - * @access public - * @param $im - * @param string $filename - * @return bool - */ - function imagebmp(&$im, $filename = "") - { - if (!$im) { - return false; - } - $w = imagesx($im); - $h = imagesy($im); - $result = ''; - - // if the image is not true color, we convert it first - if (!imageistruecolor($im)) { - $tmp = imagecreatetruecolor($w, $h); - imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h); - imagedestroy($im); - $im = &$tmp; - } - - $biBPLine = $w * 3; - $biStride = ($biBPLine + 3) & ~3; - $biSizeImage = $biStride * $h; - $bfOffBits = 54; - $bfSize = $bfOffBits + $biSizeImage; - - $result .= substr('BM', 0, 2); - $result .= pack('VvvV', $bfSize, 0, 0, $bfOffBits); - $result .= pack('VVVvvVVVVVV', 40, $w, $h, 1, 24, 0, $biSizeImage, 0, 0, 0, 0); - - $numpad = $biStride - $biBPLine; - for ($y = $h - 1; $y >= 0; --$y) { - for ($x = 0; $x < $w; ++$x) { - $col = imagecolorat($im, $x, $y); - $result .= substr(pack('V', $col), 0, 3); - } - for ($i = 0; $i < $numpad; ++$i) { - $result .= pack('C', 0); - } - } - - if ($filename == "") { - echo $result; - } else { - $file = fopen($filename, "wb"); - fwrite($file, $result); - fclose($file); - } - - return true; - } -} diff --git a/src/Validator.php b/src/Validator.php deleted file mode 100644 index 4793689..0000000 --- a/src/Validator.php +++ /dev/null @@ -1,135 +0,0 @@ -()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/"; - const V_PASS = "/^([A-Z,a-z,0-9,.,_,-,@,#,&,<,>]*)$/"; - const V_SHA1 = "/^[0-9a-f]{40,40}$/"; - - ##APPLICATION DATA - const V_ID = "/^[0-9]{1,20}$/"; - const V_HEX = "/^[0-9a-fA-F]*$/"; - const V_BOOLEAN = "/^[0-1]{1,1}$/"; - const V_TITLE = '/^([A-Z0-9a-z\-ºª,.!?:;@#%&*ÂÀÁÄÃâãàáäÊÈÉËêèéëÎÍÌÏîíìïÔÕÒÓÖôõòóöÛÙÚÜûúùüÇç\[\]+\\\\\'" ])*$/'; - const V_LINK = '%^(?:(?:https?|ftp)://)?(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\n]*)?$%iu'; - const V_PERMALINK = "/([a-zA-Z0-9\\-_.,+])*/"; - const V_FILENAME = "/([a-zA-Z0-9\\-_.,+])*.([a-zA-Z]{3,3})/"; - - ##USER DATA - const V_NAME = "/^[A-Za-zÂÀÁÄÃâãàáäÊÈÉËêèéëÎÍÌÏîíìïÔÕÒÓÖôõòóöÛÙÚÜûúùüÇç. ]*$/"; - const V_MOBILE = "/^[0-9]*$/"; - const V_SEX = "/^([mfMF]{1,1})$/"; - const V_STATE_BR = "/^(GO|MT|MS|DF|AM|AC|RO|RR|AP|TO|PA|MA|PI|CE|RN|PB|PE|SE|AL|RS|SC|PR|ES|BA|SP|MG|RJ)$/"; - const V_CEP_BR = "/^([0-9]{5,8})$/"; - - ##SPECIFIC DATA - const V_TWITTER = "/^((http:\/\/)|(https:\/\/))?(www\.)?twitter\.com\/(#!\/)?([A-Za-z0-9\/])+$/"; - const V_FACEBOOK = "/^((http:\/\/)|(https:\/\/))?(www\.)?facebook\.com\/([A-Z,a-z,0-9,@,%,#,!,&,*,+,:,?,_,=,.,\/]|[,]|[-])+$/"; - const V_YOUTUBE = "/^((http:\/\/)|(https:\/\/))?(www\.)?((youtube\.com)|(youtu\.be))\/([A-Z,a-z,0-9,@,#,!,&,*,+,:,?,_,=,.,\/]|[,]|[-])+$/"; - const V_INSTAGRAM = "/^((http:\/\/)|(https:\/\/))?(www\.)?instagram\.com\/([A-Z,a-z,0-9,@,#,!,&,*,+,:,?,_,=,.,\/]|[,]|[-])+$/"; - - /** - * This function is used to validate a variable via a regular expression - * - * @param string $regex A regular expression. You can use one of the defined above or one of your own creation - * @param string $var String variable to be validated - * - * @return bool is the value is valid - */ - public static function validate($regex, $var) : bool - { - return preg_match($regex, $var) == 1; - } - - /** - * This function chekcs whether a given string is UTF-8 - * - * @param string $string String to be checked - * - * @return bool if the encoding is UTF-8 - */ - public static function isUTF8(string $string) : bool - { - return mb_detect_encoding($string, 'UTF-8', true) == 'UTF-8'; - } - - /** - * This function is used to sanitize a given string - * - * @param string $string String variable to be sanitized - * - * @return string Returns the string trimmed, without tags and encoded with htmlspecialchars - */ - public static function sanitize(string $string) : string - { - return htmlspecialchars(strip_tags(trim($string)), ENT_QUOTES); - } - - /** - * Remove the protocol and the last '/' from a given URL - * - * @param string $url URL to be sanitized - * - * @return string The string without protocol (http[s]://) and the last / - */ - public static function sanitizeUrl(string $url) : string - { - $url_no_protocol = $url; - if (stristr($url, "https://")) { - $tmp = explode("https://", $url); - $url_no_protocol = $tmp[1]; - } else { - if (stristr($url, "http://")) { - $tmp = explode("http://", $url); - $url_no_protocol = $tmp[1]; - } - } - - if ($url_no_protocol == '') { - return ''; - } - - return rtrim($url_no_protocol, '/'); - } - - /** - * This function is used to validate a CPF (Cadastro de Pessoa F�sica) number. - * - * @param string $cpf CPF as string containing only numbers (no points or score) - * - * @return bool - */ - public static function valCPF($cpf) - { - $cpf = str_replace('.', '', str_replace('-', '', $cpf)); - $cpf = str_pad(ereg_replace('[^0-9]', '', $cpf), 11, '0', STR_PAD_LEFT); - - if (strlen($cpf) != 11 || $cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' || $cpf == '33333333333' || $cpf == '44444444444' || $cpf == '55555555555' || $cpf == '66666666666' || $cpf == '77777777777' || $cpf == '88888888888' || $cpf == '99999999999') { - return false; - } else { - for ($t = 9; $t < 11; $t++) { - for ($d = 0, $c = 0; $c < $t; $c++) { - $d += $cpf{$c} * (($t + 1) - $c); - } - $d = ((10 * $d) % 11) % 10; - if ($cpf{$c} != $d) { - return false; - } - } - - return true; - } - } - -} diff --git a/tests/Services/Google/DistanceMatrixLocationTest.php b/tests/Services/Google/DistanceMatrixLocationTest.php deleted file mode 100644 index bfa7bfa..0000000 --- a/tests/Services/Google/DistanceMatrixLocationTest.php +++ /dev/null @@ -1,83 +0,0 @@ -assertEquals('Canada', $location->getFormattedLocation()); - } - - public function testFormatStateLocation() - { - $location = new DistanceMatrixLocation('Canada', 'BC'); - - $this->assertEquals('BC+Canada', $location->getFormattedLocation()); - } - - public function testFormatCityLocation() - { - $location = new DistanceMatrixLocation('Canada', 'BC', 'Vancouver'); - - $this->assertEquals('Vancouver+BC+Canada', $location->getFormattedLocation()); - } - - public function testFormatCoordinatesLocation() - { - $location = new DistanceMatrixLocation( - null, - null, - null, - null, - '49.252784', - '-123.108113' - ); - - $this->assertEquals('49.252784,-123.108113', $location->getFormattedLocation()); - } - - public function testFormatZipCodeLocation() - { - $location = new DistanceMatrixLocation( - null, - null, - null, - null, - null, - null, - 'ChIJpekq4O9zhlQRUNNS_bu6dEM' - ); - - $this->assertEquals('place_id:ChIJpekq4O9zhlQRUNNS_bu6dEM', $location->getFormattedLocation()); - } - - public function testFormatCompleteAddressLocation() - { - $location = new DistanceMatrixLocation( - null, - null, - null, - null, - null, - null, - null, - '98-025 Hekaha Street, Suite 205 , Honolulu, HI' - ); - - $this->assertEquals('98-025+Hekaha+Street,+Suite+205+,+Honolulu,+HI', $location->getFormattedLocation()); - } -} diff --git a/tests/Time/DateIntervalTest.php b/tests/Time/DateIntervalTest.php deleted file mode 100644 index bb6209f..0000000 --- a/tests/Time/DateIntervalTest.php +++ /dev/null @@ -1,57 +0,0 @@ -assertEquals(1, $interval->toYears()); - } - - public function testToMonths() - { - $now = time(); - $interval = new DateInterval($now - (60 * Time::DAY), $now); - $this->assertEquals(2, $interval->toMonths()); - } - - public function testToDays() - { - $now = time(); - $interval = new DateInterval($now - (5 * Time::DAY), $now); - $this->assertEquals(5, $interval->toDays()); - } - - public function testToHours() - { - $now = time(); - $interval = new DateInterval($now - (10 * Time::HOUR), $now); - $this->assertEquals(10, $interval->toHours()); - } - - public function testToMinutes() - { - $now = time(); - $interval = new DateInterval($now - (20 * Time::MINUTE), $now); - $this->assertEquals(20, $interval->toMinutes()); - } - - public function testToSeconds() - { - $now = time(); - $interval = new DateInterval($now - (10 * Time::SECOND), $now); - $this->assertEquals(10, $interval->toSeconds()); - } -} diff --git a/tests/TimeTest.php b/tests/TimeTest.php deleted file mode 100644 index 92921ba..0000000 --- a/tests/TimeTest.php +++ /dev/null @@ -1,74 +0,0 @@ -assertEquals('1291118730', $time->__toString()); - } - - public function testUnixtTimestamp() - { - $time = new Time('2010-11-30 12:05:30'); - $this->assertEquals('1291118730', $time->getUnixTstamp()); - } - - public function testGetTstamp() - { - $time = new Time(1291118730); - $this->assertEquals('2010-11-30 12:05:30', $time->getTstamp()); - } - - public function testGetPieces() - { - $time = new Time(1494227104); - $this->assertEquals('2017', $time->getYear()); - $this->assertEquals('05', $time->getMonth()); - $this->assertEquals('08', $time->getDay()); - $this->assertEquals('8', $time->getDayNoZero()); - $this->assertEquals('07', $time->getHours()); - $this->assertEquals('05', $time->getMinutes()); - $this->assertEquals('04', $time->getSeconds()); - } - - public function testArithmetic() - { - $time = new Time(1494227104); - $time->add(Time::DAY); - $this->assertEquals('09', $time->getDay()); - $time->subtract(Time::HOUR); - $this->assertEquals('06', $time->getHours()); - } - - public function testDiff() - { - $time = new Time(1494227104); - $dateInterval = $time->diff(1494227164); - $this->assertEquals('Frogg\Time\DateInterval', get_class($dateInterval)); - } - - public function testMask() - { - $time = new Time(1494227104); - $this->assertEquals('07:05:04 08/05/2017', $time->format('H:i:s d/m/Y')); - } - - public function testConversion() - { - $this->assertEquals(120, Time::secondsFromMinutes(2)); - $this->assertEquals(7200, Time::secondsFromHours(2)); - $this->assertEquals(86400, Time::secondsFromDays(1)); - } - -} \ No newline at end of file diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php deleted file mode 100644 index 72640b4..0000000 --- a/tests/ValidatorTest.php +++ /dev/null @@ -1,42 +0,0 @@ -assertTrue(Validator::validate(Validator::V_NAME, 'Peter')); - $this->assertFalse(Validator::validate(Validator::V_NAME, 'M4r1o')); - $this->assertTrue(Validator::validate(Validator::V_EMAIL, 'valid@email.com')); - $this->assertFalse(Validator::validate(Validator::V_EMAIL, 'inv@lid@email.!com')); - } - - public function testIsUTF8() - { - $this->assertTrue(Validator::isUTF8('This is UTF-8 encoded')); - $this->assertFalse(Validator::isUTF8("\xc3\x28")); - } - - public function testSanitize() - { - $this->assertEquals('< ola', Validator::sanitize('< ola ')); - $this->assertEquals('alert('oi');', Validator::sanitize('')); - } - - public function testSanitizeUrl() - { - $this->assertEquals('mydomain.com', Validator::sanitizeUrl('https://mydomain.com/')); - $this->assertEquals('mydomain.com/nice', Validator::sanitizeUrl('http://mydomain.com/nice/')); - $this->assertEquals('www.mydomain.com', Validator::sanitizeUrl('http://www.mydomain.com')); - } - -} \ No newline at end of file