├── .gitignore ├── LICENSE ├── README.md ├── autoload.php ├── composer.json ├── sample ├── composer.json ├── composer.lock ├── content │ └── koala_mini.jpg ├── index.php ├── koala.jpg ├── koala_mini.jpg └── vendor │ ├── autoload.php │ ├── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ ├── autoload_static.php │ └── installed.json │ └── eihror │ └── compress-image │ ├── .gitignore │ ├── Examples │ ├── content │ │ └── koala_mini.jpg │ ├── index.php │ ├── koala.jpg │ └── koala_mini.jpg │ ├── LICENSE │ ├── README.md │ ├── autoload.php │ ├── composer.json │ └── src │ └── Compress.php └── src └── Compress.php /.gitignore: -------------------------------------------------------------------------------- 1 | nbproject 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Igor Melo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Stable Version](https://poser.pugx.org/eihror/compress-image/v/stable)](https://packagist.org/packages/eihror/compress-image) 2 | [![Total Downloads](https://poser.pugx.org/eihror/compress-image/downloads)](https://packagist.org/packages/eihror/compress-image) 3 | [![Latest Unstable Version](https://poser.pugx.org/eihror/compress-image/v/unstable)](https://packagist.org/packages/eihror/compress-image) 4 | [![License](https://poser.pugx.org/eihror/compress-image/license)](https://packagist.org/packages/eihror/compress-image) 5 | 6 | # Compress Image 7 | 8 | Compress your image without losing quality 9 | 10 | ## How to use 11 | 12 | Clone this project inside the project that you want to use 13 | 14 | ``` 15 | composer require eihror/compress-image 16 | ``` 17 | 18 | Create variables to receive the elements 19 | 20 | ``` 21 | $file = 'koala.jpg'; //file that you wanna compress 22 | $new_name_image = 'koala_mini'; //name of new file compressed 23 | $quality = 60; // Value that I chose 24 | $pngQuality = 9; // Exclusive for PNG files 25 | $destination = 'content'; //This destination must be exist on your project 26 | $maxsize = 5245330; //Set maximum image size in bytes. if no value given 5mb by default. 27 | ``` 28 | 29 | **The quality works only for JPG�s images. But if you want to change the file to PNG�s, you have to change manually via code. GIF doesn't affect the quality** 30 | 31 | Default quality for PNG: **9 ( 0 - no compression, 9 - max compression )** 32 | Create a new instance of a class 33 | 34 | ``` 35 | $image_compress = new Eihror\Compress\Compress($file, $new_name_image, $quality, $pngQuality, $destination, $maxsize); 36 | ``` 37 | 38 | And make the compression calling the function **compress_image** 39 | 40 | ``` 41 | $image_compress->compress_image(); 42 | ``` 43 | 44 | This function will return only the name of new image compressed with your respective extension 45 | 46 | That´s it! Feel free to use and making the code better if you find something different or wrong 47 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | =5.3.0" 11 | }, 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Eihror", 16 | "email": "igor_gmelo@hotmail.com", 17 | "homepage": "http://www.igormelo.com", 18 | "role": "Developer" 19 | } 20 | ], 21 | "autoload": { 22 | "classmap": [ 23 | "src" 24 | ], 25 | "psr-4": {"Eihror\\Compress\\": "src"} 26 | }, 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "1.0.x-dev" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "eihror/compress-image": "^0.0.5" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "efef452a5e14b07f7d533128cb46b409", 8 | "packages": [ 9 | { 10 | "name": "eihror/compress-image", 11 | "version": "v0.0.5", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/eihror/compress-image.git", 15 | "reference": "a546014546298b4718f2f9d0477f1e170e559b95" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/eihror/compress-image/zipball/a546014546298b4718f2f9d0477f1e170e559b95", 20 | "reference": "a546014546298b4718f2f9d0477f1e170e559b95", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=5.3.0" 25 | }, 26 | "type": "library", 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "1.0.x-dev" 30 | } 31 | }, 32 | "autoload": { 33 | "classmap": [ 34 | "src" 35 | ], 36 | "psr-4": { 37 | "Eihror\\Compress\\": "src" 38 | } 39 | }, 40 | "notification-url": "https://packagist.org/downloads/", 41 | "license": [ 42 | "MIT" 43 | ], 44 | "authors": [ 45 | { 46 | "name": "Eihror", 47 | "email": "igor_gmelo@hotmail.com", 48 | "homepage": "http://www.igormelo.com", 49 | "role": "Developer" 50 | } 51 | ], 52 | "description": "Compress your image without losing quality", 53 | "homepage": "https://github.com/eihror/compress-image", 54 | "time": "2018-08-03T18:52:14+00:00" 55 | } 56 | ], 57 | "packages-dev": [], 58 | "aliases": [], 59 | "minimum-stability": "stable", 60 | "stability-flags": [], 61 | "prefer-stable": false, 62 | "prefer-lowest": false, 63 | "platform": [], 64 | "platform-dev": [] 65 | } 66 | -------------------------------------------------------------------------------- /sample/content/koala_mini.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eihror/compress-image/2e2e3e6c6b7ea9edd9d18193554245a16904fcbf/sample/content/koala_mini.jpg -------------------------------------------------------------------------------- /sample/index.php: -------------------------------------------------------------------------------- 1 | compress_image(); 18 | -------------------------------------------------------------------------------- /sample/koala.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eihror/compress-image/2e2e3e6c6b7ea9edd9d18193554245a16904fcbf/sample/koala.jpg -------------------------------------------------------------------------------- /sample/koala_mini.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eihror/compress-image/2e2e3e6c6b7ea9edd9d18193554245a16904fcbf/sample/koala_mini.jpg -------------------------------------------------------------------------------- /sample/vendor/autoload.php: -------------------------------------------------------------------------------- 1 | 7 | * Jordi Boggiano 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier 39 | * @author Jordi Boggiano 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | private $classMapAuthoritative = false; 57 | private $missingClasses = array(); 58 | private $apcuPrefix; 59 | 60 | public function getPrefixes() 61 | { 62 | if (!empty($this->prefixesPsr0)) { 63 | return call_user_func_array('array_merge', $this->prefixesPsr0); 64 | } 65 | 66 | return array(); 67 | } 68 | 69 | public function getPrefixesPsr4() 70 | { 71 | return $this->prefixDirsPsr4; 72 | } 73 | 74 | public function getFallbackDirs() 75 | { 76 | return $this->fallbackDirsPsr0; 77 | } 78 | 79 | public function getFallbackDirsPsr4() 80 | { 81 | return $this->fallbackDirsPsr4; 82 | } 83 | 84 | public function getClassMap() 85 | { 86 | return $this->classMap; 87 | } 88 | 89 | /** 90 | * @param array $classMap Class to filename map 91 | */ 92 | public function addClassMap(array $classMap) 93 | { 94 | if ($this->classMap) { 95 | $this->classMap = array_merge($this->classMap, $classMap); 96 | } else { 97 | $this->classMap = $classMap; 98 | } 99 | } 100 | 101 | /** 102 | * Registers a set of PSR-0 directories for a given prefix, either 103 | * appending or prepending to the ones previously set for this prefix. 104 | * 105 | * @param string $prefix The prefix 106 | * @param array|string $paths The PSR-0 root directories 107 | * @param bool $prepend Whether to prepend the directories 108 | */ 109 | public function add($prefix, $paths, $prepend = false) 110 | { 111 | if (!$prefix) { 112 | if ($prepend) { 113 | $this->fallbackDirsPsr0 = array_merge( 114 | (array) $paths, 115 | $this->fallbackDirsPsr0 116 | ); 117 | } else { 118 | $this->fallbackDirsPsr0 = array_merge( 119 | $this->fallbackDirsPsr0, 120 | (array) $paths 121 | ); 122 | } 123 | 124 | return; 125 | } 126 | 127 | $first = $prefix[0]; 128 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 130 | 131 | return; 132 | } 133 | if ($prepend) { 134 | $this->prefixesPsr0[$first][$prefix] = array_merge( 135 | (array) $paths, 136 | $this->prefixesPsr0[$first][$prefix] 137 | ); 138 | } else { 139 | $this->prefixesPsr0[$first][$prefix] = array_merge( 140 | $this->prefixesPsr0[$first][$prefix], 141 | (array) $paths 142 | ); 143 | } 144 | } 145 | 146 | /** 147 | * Registers a set of PSR-4 directories for a given namespace, either 148 | * appending or prepending to the ones previously set for this namespace. 149 | * 150 | * @param string $prefix The prefix/namespace, with trailing '\\' 151 | * @param array|string $paths The PSR-4 base directories 152 | * @param bool $prepend Whether to prepend the directories 153 | * 154 | * @throws \InvalidArgumentException 155 | */ 156 | public function addPsr4($prefix, $paths, $prepend = false) 157 | { 158 | if (!$prefix) { 159 | // Register directories for the root namespace. 160 | if ($prepend) { 161 | $this->fallbackDirsPsr4 = array_merge( 162 | (array) $paths, 163 | $this->fallbackDirsPsr4 164 | ); 165 | } else { 166 | $this->fallbackDirsPsr4 = array_merge( 167 | $this->fallbackDirsPsr4, 168 | (array) $paths 169 | ); 170 | } 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 172 | // Register directories for a new namespace. 173 | $length = strlen($prefix); 174 | if ('\\' !== $prefix[$length - 1]) { 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 176 | } 177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 179 | } elseif ($prepend) { 180 | // Prepend directories for an already registered namespace. 181 | $this->prefixDirsPsr4[$prefix] = array_merge( 182 | (array) $paths, 183 | $this->prefixDirsPsr4[$prefix] 184 | ); 185 | } else { 186 | // Append directories for an already registered namespace. 187 | $this->prefixDirsPsr4[$prefix] = array_merge( 188 | $this->prefixDirsPsr4[$prefix], 189 | (array) $paths 190 | ); 191 | } 192 | } 193 | 194 | /** 195 | * Registers a set of PSR-0 directories for a given prefix, 196 | * replacing any others previously set for this prefix. 197 | * 198 | * @param string $prefix The prefix 199 | * @param array|string $paths The PSR-0 base directories 200 | */ 201 | public function set($prefix, $paths) 202 | { 203 | if (!$prefix) { 204 | $this->fallbackDirsPsr0 = (array) $paths; 205 | } else { 206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 207 | } 208 | } 209 | 210 | /** 211 | * Registers a set of PSR-4 directories for a given namespace, 212 | * replacing any others previously set for this namespace. 213 | * 214 | * @param string $prefix The prefix/namespace, with trailing '\\' 215 | * @param array|string $paths The PSR-4 base directories 216 | * 217 | * @throws \InvalidArgumentException 218 | */ 219 | public function setPsr4($prefix, $paths) 220 | { 221 | if (!$prefix) { 222 | $this->fallbackDirsPsr4 = (array) $paths; 223 | } else { 224 | $length = strlen($prefix); 225 | if ('\\' !== $prefix[$length - 1]) { 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 227 | } 228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 230 | } 231 | } 232 | 233 | /** 234 | * Turns on searching the include path for class files. 235 | * 236 | * @param bool $useIncludePath 237 | */ 238 | public function setUseIncludePath($useIncludePath) 239 | { 240 | $this->useIncludePath = $useIncludePath; 241 | } 242 | 243 | /** 244 | * Can be used to check if the autoloader uses the include path to check 245 | * for classes. 246 | * 247 | * @return bool 248 | */ 249 | public function getUseIncludePath() 250 | { 251 | return $this->useIncludePath; 252 | } 253 | 254 | /** 255 | * Turns off searching the prefix and fallback directories for classes 256 | * that have not been registered with the class map. 257 | * 258 | * @param bool $classMapAuthoritative 259 | */ 260 | public function setClassMapAuthoritative($classMapAuthoritative) 261 | { 262 | $this->classMapAuthoritative = $classMapAuthoritative; 263 | } 264 | 265 | /** 266 | * Should class lookup fail if not found in the current class map? 267 | * 268 | * @return bool 269 | */ 270 | public function isClassMapAuthoritative() 271 | { 272 | return $this->classMapAuthoritative; 273 | } 274 | 275 | /** 276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled. 277 | * 278 | * @param string|null $apcuPrefix 279 | */ 280 | public function setApcuPrefix($apcuPrefix) 281 | { 282 | $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; 283 | } 284 | 285 | /** 286 | * The APCu prefix in use, or null if APCu caching is not enabled. 287 | * 288 | * @return string|null 289 | */ 290 | public function getApcuPrefix() 291 | { 292 | return $this->apcuPrefix; 293 | } 294 | 295 | /** 296 | * Registers this instance as an autoloader. 297 | * 298 | * @param bool $prepend Whether to prepend the autoloader or not 299 | */ 300 | public function register($prepend = false) 301 | { 302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 303 | } 304 | 305 | /** 306 | * Unregisters this instance as an autoloader. 307 | */ 308 | public function unregister() 309 | { 310 | spl_autoload_unregister(array($this, 'loadClass')); 311 | } 312 | 313 | /** 314 | * Loads the given class or interface. 315 | * 316 | * @param string $class The name of the class 317 | * @return bool|null True if loaded, null otherwise 318 | */ 319 | public function loadClass($class) 320 | { 321 | if ($file = $this->findFile($class)) { 322 | includeFile($file); 323 | 324 | return true; 325 | } 326 | } 327 | 328 | /** 329 | * Finds the path to the file where the class is defined. 330 | * 331 | * @param string $class The name of the class 332 | * 333 | * @return string|false The path if found, false otherwise 334 | */ 335 | public function findFile($class) 336 | { 337 | // class map lookup 338 | if (isset($this->classMap[$class])) { 339 | return $this->classMap[$class]; 340 | } 341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 342 | return false; 343 | } 344 | if (null !== $this->apcuPrefix) { 345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit); 346 | if ($hit) { 347 | return $file; 348 | } 349 | } 350 | 351 | $file = $this->findFileWithExtension($class, '.php'); 352 | 353 | // Search for Hack files if we are running on HHVM 354 | if (false === $file && defined('HHVM_VERSION')) { 355 | $file = $this->findFileWithExtension($class, '.hh'); 356 | } 357 | 358 | if (null !== $this->apcuPrefix) { 359 | apcu_add($this->apcuPrefix.$class, $file); 360 | } 361 | 362 | if (false === $file) { 363 | // Remember that this class does not exist. 364 | $this->missingClasses[$class] = true; 365 | } 366 | 367 | return $file; 368 | } 369 | 370 | private function findFileWithExtension($class, $ext) 371 | { 372 | // PSR-4 lookup 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 374 | 375 | $first = $class[0]; 376 | if (isset($this->prefixLengthsPsr4[$first])) { 377 | $subPath = $class; 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { 379 | $subPath = substr($subPath, 0, $lastPos); 380 | $search = $subPath . '\\'; 381 | if (isset($this->prefixDirsPsr4[$search])) { 382 | $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { 384 | if (file_exists($file = $dir . $pathEnd)) { 385 | return $file; 386 | } 387 | } 388 | } 389 | } 390 | } 391 | 392 | // PSR-4 fallback dirs 393 | foreach ($this->fallbackDirsPsr4 as $dir) { 394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 395 | return $file; 396 | } 397 | } 398 | 399 | // PSR-0 lookup 400 | if (false !== $pos = strrpos($class, '\\')) { 401 | // namespaced class name 402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 404 | } else { 405 | // PEAR-like class name 406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 407 | } 408 | 409 | if (isset($this->prefixesPsr0[$first])) { 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 411 | if (0 === strpos($class, $prefix)) { 412 | foreach ($dirs as $dir) { 413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 414 | return $file; 415 | } 416 | } 417 | } 418 | } 419 | } 420 | 421 | // PSR-0 fallback dirs 422 | foreach ($this->fallbackDirsPsr0 as $dir) { 423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 424 | return $file; 425 | } 426 | } 427 | 428 | // PSR-0 include paths. 429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 430 | return $file; 431 | } 432 | 433 | return false; 434 | } 435 | } 436 | 437 | /** 438 | * Scope isolated include. 439 | * 440 | * Prevents access to $this/self from included files. 441 | */ 442 | function includeFile($file) 443 | { 444 | include $file; 445 | } 446 | -------------------------------------------------------------------------------- /sample/vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Nils Adermann, Jordi Boggiano 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is furnished 9 | to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /sample/vendor/composer/autoload_classmap.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/eihror/compress-image/src/Compress.php', 10 | ); 11 | -------------------------------------------------------------------------------- /sample/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($vendorDir . '/eihror/compress-image/src'), 10 | ); 11 | -------------------------------------------------------------------------------- /sample/vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 27 | if ($useStaticLoader) { 28 | require_once __DIR__ . '/autoload_static.php'; 29 | 30 | call_user_func(\Composer\Autoload\ComposerStaticInitc651d6d64708981b0b083b97682ff7fe::getInitializer($loader)); 31 | } else { 32 | $map = require __DIR__ . '/autoload_namespaces.php'; 33 | foreach ($map as $namespace => $path) { 34 | $loader->set($namespace, $path); 35 | } 36 | 37 | $map = require __DIR__ . '/autoload_psr4.php'; 38 | foreach ($map as $namespace => $path) { 39 | $loader->setPsr4($namespace, $path); 40 | } 41 | 42 | $classMap = require __DIR__ . '/autoload_classmap.php'; 43 | if ($classMap) { 44 | $loader->addClassMap($classMap); 45 | } 46 | } 47 | 48 | $loader->register(true); 49 | 50 | return $loader; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Eihror\\Compress\\' => 16, 13 | ), 14 | ); 15 | 16 | public static $prefixDirsPsr4 = array ( 17 | 'Eihror\\Compress\\' => 18 | array ( 19 | 0 => __DIR__ . '/..' . '/eihror/compress-image/src', 20 | ), 21 | ); 22 | 23 | public static $classMap = array ( 24 | 'Compress' => __DIR__ . '/..' . '/eihror/compress-image/src/Compress.php', 25 | ); 26 | 27 | public static function getInitializer(ClassLoader $loader) 28 | { 29 | return \Closure::bind(function () use ($loader) { 30 | $loader->prefixLengthsPsr4 = ComposerStaticInitc651d6d64708981b0b083b97682ff7fe::$prefixLengthsPsr4; 31 | $loader->prefixDirsPsr4 = ComposerStaticInitc651d6d64708981b0b083b97682ff7fe::$prefixDirsPsr4; 32 | $loader->classMap = ComposerStaticInitc651d6d64708981b0b083b97682ff7fe::$classMap; 33 | 34 | }, null, ClassLoader::class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample/vendor/composer/installed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "eihror/compress-image", 4 | "version": "v0.0.5", 5 | "version_normalized": "0.0.5.0", 6 | "source": { 7 | "type": "git", 8 | "url": "https://github.com/eihror/compress-image.git", 9 | "reference": "a546014546298b4718f2f9d0477f1e170e559b95" 10 | }, 11 | "dist": { 12 | "type": "zip", 13 | "url": "https://api.github.com/repos/eihror/compress-image/zipball/a546014546298b4718f2f9d0477f1e170e559b95", 14 | "reference": "a546014546298b4718f2f9d0477f1e170e559b95", 15 | "shasum": "" 16 | }, 17 | "require": { 18 | "php": ">=5.3.0" 19 | }, 20 | "time": "2018-08-03T18:52:14+00:00", 21 | "type": "library", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "1.0.x-dev" 25 | } 26 | }, 27 | "installation-source": "dist", 28 | "autoload": { 29 | "classmap": [ 30 | "src" 31 | ], 32 | "psr-4": { 33 | "Eihror\\Compress\\": "src" 34 | } 35 | }, 36 | "notification-url": "https://packagist.org/downloads/", 37 | "license": [ 38 | "MIT" 39 | ], 40 | "authors": [ 41 | { 42 | "name": "Eihror", 43 | "email": "igor_gmelo@hotmail.com", 44 | "homepage": "http://www.igormelo.com", 45 | "role": "Developer" 46 | } 47 | ], 48 | "description": "Compress your image without losing quality", 49 | "homepage": "https://github.com/eihror/compress-image" 50 | } 51 | ] 52 | -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/.gitignore: -------------------------------------------------------------------------------- 1 | nbproject 2 | -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/Examples/content/koala_mini.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eihror/compress-image/2e2e3e6c6b7ea9edd9d18193554245a16904fcbf/sample/vendor/eihror/compress-image/Examples/content/koala_mini.jpg -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/Examples/index.php: -------------------------------------------------------------------------------- 1 | compress_image(); 18 | -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/Examples/koala.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eihror/compress-image/2e2e3e6c6b7ea9edd9d18193554245a16904fcbf/sample/vendor/eihror/compress-image/Examples/koala.jpg -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/Examples/koala_mini.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eihror/compress-image/2e2e3e6c6b7ea9edd9d18193554245a16904fcbf/sample/vendor/eihror/compress-image/Examples/koala_mini.jpg -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Igor Melo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/README.md: -------------------------------------------------------------------------------- 1 | [![Latest Stable Version](https://poser.pugx.org/eihror/compress-image/v/stable)](https://packagist.org/packages/eihror/compress-image) 2 | [![Total Downloads](https://poser.pugx.org/eihror/compress-image/downloads)](https://packagist.org/packages/eihror/compress-image) 3 | [![Latest Unstable Version](https://poser.pugx.org/eihror/compress-image/v/unstable)](https://packagist.org/packages/eihror/compress-image) 4 | [![License](https://poser.pugx.org/eihror/compress-image/license)](https://packagist.org/packages/eihror/compress-image) 5 | 6 | # Compress Image 7 | 8 | Compress your image without losing quality 9 | 10 | ## How to use 11 | 12 | Clone this project inside the project that you want to use 13 | 14 | ``` 15 | composer require eihror/compress-image 16 | ``` 17 | 18 | Create variables to receive the elements 19 | 20 | ``` 21 | $file = 'koala.jpg'; //file that you wanna compress 22 | $new_name_image = 'koala_mini'; //name of new file compressed 23 | $quality = 60; // Value that I chose 24 | $pngQuality = 9; // Exclusive for PNG files 25 | $destination = 'content'; //This destination must be exist on your project 26 | ``` 27 | 28 | Create a new instance of a class 29 | 30 | ``` 31 | $image_compress = new Compress($file, $new_name_image, $quality, $pngQuality, $destination); 32 | ``` 33 | 34 | And make the compression calling the funcion **compress_image** 35 | 36 | ``` 37 | $image_compress->compress_image(); 38 | ``` 39 | 40 | This funtion will return only the name of new image compressed with your respective extension 41 | 42 | That´s it! Feel free to use and making the code better if you find something different or wrong -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/autoload.php: -------------------------------------------------------------------------------- 1 | =5.3.0" 11 | }, 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Eihror", 16 | "email": "igor_gmelo@hotmail.com", 17 | "homepage": "http://www.igormelo.com", 18 | "role": "Developer" 19 | } 20 | ], 21 | "autoload": { 22 | "classmap": [ 23 | "src" 24 | ], 25 | "psr-4": {"Eihror\\Compress\\": "src"} 26 | }, 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "1.0.x-dev" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/vendor/eihror/compress-image/src/Compress.php: -------------------------------------------------------------------------------- 1 | set_file_url($file_url); 36 | $this->set_new_name_image($new_name_image); 37 | $this->set_quality($quality); 38 | $this->set_destination($destination); 39 | } 40 | 41 | function get_file_url() { 42 | return $this->file_url; 43 | } 44 | 45 | function get_new_name_image() { 46 | return $this->new_name_image; 47 | } 48 | 49 | function get_quality() { 50 | return $this->quality; 51 | } 52 | 53 | function get_pngQuality() { 54 | return $this->pngQuality; 55 | } 56 | 57 | function set_file_url($file_url) { 58 | $this->file_url = $file_url; 59 | } 60 | 61 | function set_new_name_image($new_name_image) { 62 | $this->new_name_image = $new_name_image; 63 | } 64 | 65 | function set_quality($quality) { 66 | $this->quality = $quality; 67 | } 68 | 69 | function set_pngQuality($pngQuality) { 70 | $this->pngQuality = $pngQuality; 71 | } 72 | 73 | function get_destination() { 74 | return $this->destination; 75 | } 76 | 77 | function set_destination($destination) { 78 | $this->destination = $destination; 79 | } 80 | 81 | /** 82 | * Function to compress image 83 | * @return boolean 84 | * @throws Exception 85 | */ 86 | public function compress_image(){ 87 | 88 | //Send image array 89 | $array_img_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'); 90 | $new_image = null; 91 | $last_char = null; 92 | $image_extension = null; 93 | $destination_extension = null; 94 | $png_compression = null; 95 | $maxsize = 5245330; 96 | 97 | try{ 98 | 99 | //If not found the file 100 | if(empty($this->file_url) && !file_exists($this->file_url)){ 101 | throw new Exception('Please inform the image!'); 102 | return false; 103 | } 104 | 105 | //Get image width, height, mimetype, etc.. 106 | $image_data = getimagesize($this->file_url); 107 | //Set MimeType on variable 108 | $image_mime = $image_data['mime']; 109 | 110 | //Verifiy if the file is a image 111 | if(!in_array($image_mime, $array_img_types)){ 112 | throw new Exception('Please send a image!'); 113 | return false; 114 | } 115 | 116 | //Get file size 117 | $image_size = filesize($this->file_url); 118 | 119 | //if image size is bigger than 5mb 120 | if($image_size >= $maxsize){ 121 | throw new Exception('Please send a imagem smaller than 5mb!'); 122 | return false; 123 | } 124 | 125 | //If not found the destination 126 | if(empty($this->new_name_image)){ 127 | throw new Exception('Please inform the destination name of image!'); 128 | return false; 129 | } 130 | 131 | //If not found the quality 132 | if(empty($this->quality)){ 133 | throw new Exception('Please inform the quality!'); 134 | return false; 135 | } 136 | 137 | //If not found the png quality 138 | $png_compression = (!empty($this->pngQuality)) ? $this->pngQuality : 9 ; 139 | 140 | $image_extension = pathinfo($this->file_url, PATHINFO_EXTENSION); 141 | //Verify if is sended a destination file name with extension 142 | $destination_extension = pathinfo($this->new_name_image, PATHINFO_EXTENSION); 143 | //if empty 144 | if(empty($destination_extension)){ 145 | $this->new_name_image = $this->new_name_image.'.'.$image_extension; 146 | } 147 | 148 | //Verify if folder destination isn´t empty 149 | if(!empty($this->destination)){ 150 | 151 | //And verify the last one element of value 152 | $last_char = substr($this->destination, -1); 153 | 154 | if($last_char !== '/'){ 155 | $this->destination = $this->destination.'/'; 156 | } 157 | } 158 | 159 | //Switch to find the file type 160 | switch ($image_mime){ 161 | //if is JPG and siblings 162 | case 'image/jpeg': 163 | case 'image/pjpeg': 164 | //Create a new jpg image 165 | $new_image = imagecreatefromjpeg($this->file_url); 166 | imagejpeg($new_image, $this->destination.$this->new_name_image, $this->quality); 167 | break; 168 | //if is PNG and siblings 169 | case 'image/png': 170 | case 'image/x-png': 171 | //Create a new png image 172 | $new_image = imagecreatefrompng('conteudo/'.$this->file_url); 173 | imagealphablending($new_image , false); 174 | imagesavealpha($new_image , true); 175 | imagepng($new_image, $this->destination.$this->new_name_image, $png_compression); 176 | break; 177 | // if is GIF 178 | case 'image/gif': 179 | //Create a new gif image 180 | $new_image = imagecreatefromgif('conteudo/'.$this->file_url); 181 | imagealphablending($new_image, false); 182 | imagesavealpha($new_image, true); 183 | imagegif($new_image, $this->destination.$this->new_name_image); 184 | } 185 | 186 | } catch (Exception $ex) { 187 | return $ex->getMessage(); 188 | } 189 | 190 | //Return the new image resized 191 | return $this->new_name_image; 192 | 193 | } 194 | } -------------------------------------------------------------------------------- /src/Compress.php: -------------------------------------------------------------------------------- 1 | set_file_url($file_url); 39 | $this->set_new_name_image($new_name_image); 40 | $this->set_quality($quality); 41 | $this->set_destination($destination); 42 | $this->set_maxSize($maxsize); 43 | } 44 | 45 | function get_file_url() { 46 | return $this->file_url; 47 | } 48 | 49 | function get_new_name_image() { 50 | return $this->new_name_image; 51 | } 52 | 53 | function get_quality() { 54 | return $this->quality; 55 | } 56 | 57 | function get_pngQuality() { 58 | return $this->pngQuality; 59 | } 60 | 61 | function get_maxsize() { 62 | return $this->maxSize; 63 | } 64 | 65 | function set_file_url($file_url) { 66 | $this->file_url = $file_url; 67 | } 68 | 69 | function set_new_name_image($new_name_image) { 70 | $this->new_name_image = $new_name_image; 71 | } 72 | 73 | function set_quality($quality) { 74 | $this->quality = $quality; 75 | } 76 | 77 | function set_pngQuality($pngQuality) { 78 | $this->pngQuality = $pngQuality; 79 | } 80 | 81 | function get_destination() { 82 | return $this->destination; 83 | } 84 | 85 | function set_destination($destination) { 86 | $this->destination = $destination; 87 | } 88 | 89 | function set_maxSize($maxsize) { 90 | $this->maxSize = $maxsize; 91 | } 92 | 93 | /** 94 | * Function to compress image 95 | * @return boolean 96 | * @throws Exception 97 | */ 98 | public function compress_image(){ 99 | 100 | //Send image array 101 | $array_img_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'); 102 | $new_image = null; 103 | $last_char = null; 104 | $image_extension = null; 105 | $destination_extension = null; 106 | $png_compression = null; 107 | 108 | try{ 109 | 110 | //If not found the file 111 | if(empty($this->file_url) && !file_exists($this->file_url)){ 112 | throw new Exception('Please inform the image!'); 113 | return false; 114 | } 115 | 116 | //Get image width, height, mimetype, etc.. 117 | $image_data = getimagesize($this->file_url); 118 | //Set MimeType on variable 119 | $image_mime = $image_data['mime']; 120 | 121 | //Verifiy if the file is a image 122 | if(!in_array($image_mime, $array_img_types)){ 123 | throw new Exception('Please send a image!'); 124 | return false; 125 | } 126 | 127 | //Get file size 128 | $image_size = filesize($this->file_url); 129 | 130 | //if image size is bigger than given file size. dafult it will be 5mb! 131 | if($image_size >= $this->maxSize){ 132 | throw new \Exception("Please send a imagem smaller than {$this->maxSize}bytes!"); 133 | return false; 134 | } 135 | 136 | //If not found the destination 137 | if(empty($this->new_name_image)){ 138 | throw new Exception('Please inform the destination name of image!'); 139 | return false; 140 | } 141 | 142 | //If not found the quality 143 | if(empty($this->quality)){ 144 | throw new Exception('Please inform the quality!'); 145 | return false; 146 | } 147 | 148 | //If not found the png quality 149 | $png_compression = (!empty($this->pngQuality)) ? $this->pngQuality : 9 ; 150 | 151 | $image_extension = pathinfo($this->file_url, PATHINFO_EXTENSION); 152 | //Verify if is sended a destination file name with extension 153 | $destination_extension = pathinfo($this->new_name_image, PATHINFO_EXTENSION); 154 | //if empty 155 | if(empty($destination_extension)){ 156 | $this->new_name_image = $this->new_name_image.'.'.$image_extension; 157 | } 158 | 159 | //Verify if folder destination isn´t empty 160 | if(!empty($this->destination)){ 161 | 162 | //And verify the last one element of value 163 | $last_char = substr($this->destination, -1); 164 | 165 | if($last_char !== '/'){ 166 | $this->destination = $this->destination.'/'; 167 | } 168 | } 169 | 170 | //Switch to find the file type 171 | switch ($image_mime){ 172 | //if is JPG and siblings 173 | case 'image/jpeg': 174 | case 'image/pjpeg': 175 | //Create a new jpg image 176 | $new_image = imagecreatefromjpeg($this->file_url); 177 | imagejpeg($new_image, $this->destination.$this->new_name_image, $this->quality); 178 | break; 179 | //if is PNG and siblings 180 | case 'image/png': 181 | case 'image/x-png': 182 | //Create a new png image 183 | $maxImgWidth = 900; 184 | // create image from posted file 185 | $src = imagecreatefrompng($this->file_url); 186 | // get original size of uploaded image 187 | list($width, $height) = getimagesize($this->file_url); 188 | if ($width > $maxImgWidth) 189 | { 190 | $newwidth = $maxImgWidth; 191 | $newheight = ($height / $width) * $newwidth; 192 | $newImage = imagecreate($newwidth, $newheight); 193 | imagecopyresampled($newImage, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 194 | imagepng($newImage, $this->destination.$this->new_name_image, $png_compression); 195 | imagedestroy($src); 196 | imagedestroy($newImage); 197 | $resizedFlag = true; 198 | } 199 | break; 200 | // if is GIF 201 | case 'image/gif': 202 | //Create a new gif image 203 | $new_image = imagecreatefromgif($this->file_url); 204 | imagealphablending($new_image, false); 205 | imagesavealpha($new_image, true); 206 | imagegif($new_image, $this->destination.$this->new_name_image); 207 | } 208 | 209 | } catch (Exception $ex) { 210 | return $ex->getMessage(); 211 | } 212 | 213 | //Return the new image resized 214 | return $this->new_name_image; 215 | 216 | } 217 | } 218 | --------------------------------------------------------------------------------