public static function make($file, $hash, $parameters) { $PHPicture = PHPicture::getInstance(); self::$file = pathinfo($PHPicture->imagesPath() . '/' . $file); self::$file_absolute_path = $PHPicture->imagesPath() . '/' . self::$file['basename']; $source = self::makeSource(); $sizes = getimagesize(self::$file_absolute_path); $newImage['width'] = array_key_exists('w', $parameters) ? $parameters['w'] : $sizes[0]; $newImage['height'] = array_key_exists('h', $parameters) ? $parameters['h'] : $sizes[1]; $extension = array_key_exists('f', $parameters) ? $parameters['f'] : self::$file['extension']; $hash = $hash . '.' . $extension; $quality = array_key_exists('q', $parameters) ? $parameters['q'] : 0; $aspectRatio['thumb'] = $newImage['width'] / $newImage['height']; $aspectRatio['original'] = $sizes[0] / $sizes[1]; $newImageThumb = self::aspectRatio($aspectRatio, $newImage, $sizes); $new_image_temp = imagecreatetruecolor($newImageThumb['width'], $newImageThumb['height']); imagecopyresampled($new_image_temp, $source, 0, 0, 0, 0, $newImageThumb['width'], $newImageThumb['height'], $sizes[0], $sizes[1]); $new_image = imagecreatetruecolor($newImage['width'], $newImage['height']); $backcolor = array_key_exists('b', $parameters) ? PHPTools::hexToRGB($parameters['b']) : PHPTools::color_black; $backcolor = imagecolorallocate($new_image, $backcolor[0], $backcolor[1], $backcolor[2]); imagefill($new_image, 0, 0, $backcolor); imagecopy($new_image, $new_image_temp, imagesx($new_image) / 2 - imagesx($new_image_temp) / 2, imagesy($new_image) / 2 - imagesy($new_image_temp) / 2, 0, 0, imagesx($new_image_temp), imagesy($new_image_temp)); // echo 'arquivo:'.$PHPicture->cachePath().'/'.$hash; // die; switch ($extension) { case 'png': imagepng($new_image, $PHPicture->cachePath() . '/' . $hash, $quality); break; case 'jpg': imagejpeg($new_image, $PHPicture->cachePath() . '/' . $hash, $quality); break; case 'jpeg': imagejpeg($new_image, $PHPicture->cachePath() . '/' . $hash, $quality); break; case 'gif': imagegif($new_image, $PHPicture->cachePath() . '/' . $hash, $quality); break; } $PHPicture->load($hash); }
private function makeParameters($image) { self::makeHash($this->string_original = $image); if (file_exists($this->cache_folder . '/' . $this->hash)) { $this->load($this->hash); } else { $temp = explode('.', $image); $extension = end($temp); $parameters = explode('-', array_shift($temp)); $file = array_shift($parameters) . '.' . $extension; foreach ($parameters as $value) { $tempA = explode(':', $value); $this->parameters[$tempA[0]] = $tempA[1]; } if (file_exists(parent::getApplicationPath() . parent::getConfiguration()['images_folder'] . '/' . $file)) { $this->file_original = $file; \PHPicture\Core\PHPFactory::make($this->file_original, $this->hash, $this->parameters); } else { throw new PHPictureException('Image [' . $file . '] not exists!'); } } }