@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * Если внешний линк, возвращаем что давали |
| 68 | 68 | */ |
| 69 | 69 | if (!config('convert.convert_external_url') && $this->isHTTP) { |
| 70 | - Log::info('ConvertImage. Not allowed converted external file (config): ' . $image); |
|
| 70 | + Log::info('ConvertImage. Not allowed converted external file (config): '.$image); |
|
| 71 | 71 | return $image; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | $link = $this->getNewName($newImagePath, $imageName); |
| 91 | - $image_url = Str::replace('//', '/', public_path() . '/' . $link); |
|
| 91 | + $image_url = Str::replace('//', '/', public_path().'/'.$link); |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | $bgTransparentColor = config('convert.bg_color', '#ffffff'); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $jpg->insert($img); |
| 103 | 103 | |
| 104 | 104 | if ($resize) { |
| 105 | - $jpg->resize($this->width, $this->height, function ($constraint) { |
|
| 105 | + $jpg->resize($this->width, $this->height, function($constraint) { |
|
| 106 | 106 | if (config('convert.aspect_ratio')) |
| 107 | 107 | { |
| 108 | 108 | $constraint->aspectRatio(); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | $status = $jpg->save($image_url, $this->quality, $this->format); |
| 119 | 119 | |
| 120 | 120 | } catch (Exception $e) { |
| 121 | - Log::info('ConvertImage. Cannot save converted image: ' . $link); |
|
| 121 | + Log::info('ConvertImage. Cannot save converted image: '.$link); |
|
| 122 | 122 | Log::info($e->getMessage()); |
| 123 | 123 | $image_url = $image; |
| 124 | 124 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | try { |
| 132 | 132 | $webP = $this->webpImage($image_url); |
| 133 | 133 | } catch (Exception $e) { |
| 134 | - Log::info('ConvertImage. Cannot create webP image: ' . $link); |
|
| 134 | + Log::info('ConvertImage. Cannot create webP image: '.$link); |
|
| 135 | 135 | Log::info($e->getMessage()); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -142,22 +142,22 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | if ($this->dev) { |
| 144 | 144 | |
| 145 | - $logData = "\n" . 'original: ' . $image; |
|
| 146 | - $logData .= "\n" . 'status: ' . ($status ? 'true' : 'false'); |
|
| 147 | - $logData .= "\n" . 'converted (return): ' . $link; |
|
| 148 | - $logData .= "\n" . 'overwrite file: ' . ($this->overwrite ? 'true' : 'false'); |
|
| 149 | - $logData .= "\n" . 'deleted original file: ' . ($deletedOriginal ? 'true' : 'false'); |
|
| 150 | - $logData .= "\n" . 'width: ' . $this->width; |
|
| 151 | - $logData .= "\n" . 'height: ' . $this->height; |
|
| 152 | - $logData .= "\n" . 'format: ' . $this->format; |
|
| 153 | - $logData .= "\n" . 'quality: ' . $this->quality; |
|
| 145 | + $logData = "\n".'original: '.$image; |
|
| 146 | + $logData .= "\n".'status: '.($status ? 'true' : 'false'); |
|
| 147 | + $logData .= "\n".'converted (return): '.$link; |
|
| 148 | + $logData .= "\n".'overwrite file: '.($this->overwrite ? 'true' : 'false'); |
|
| 149 | + $logData .= "\n".'deleted original file: '.($deletedOriginal ? 'true' : 'false'); |
|
| 150 | + $logData .= "\n".'width: '.$this->width; |
|
| 151 | + $logData .= "\n".'height: '.$this->height; |
|
| 152 | + $logData .= "\n".'format: '.$this->format; |
|
| 153 | + $logData .= "\n".'quality: '.$this->quality; |
|
| 154 | 154 | |
| 155 | - $logData .= "\n" . 'isHTTP: ' . ($this->isHTTP ? 'true' : 'false'); |
|
| 156 | - $logData .= "\n" . 'deleteAfterConvert: ' . ($this->deleteAfterConvert ? 'true' : 'false'); |
|
| 155 | + $logData .= "\n".'isHTTP: '.($this->isHTTP ? 'true' : 'false'); |
|
| 156 | + $logData .= "\n".'deleteAfterConvert: '.($this->deleteAfterConvert ? 'true' : 'false'); |
|
| 157 | 157 | |
| 158 | - $logData .= "\n" . 'create webP: ' . ($webP ? 'true' : 'false'); |
|
| 158 | + $logData .= "\n".'create webP: '.($webP ? 'true' : 'false'); |
|
| 159 | 159 | |
| 160 | - Log::info('ConvertImage. Dev mode ->' . $logData); |
|
| 160 | + Log::info('ConvertImage. Dev mode ->'.$logData); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -303,10 +303,10 @@ discard block |
||
| 303 | 303 | try { |
| 304 | 304 | $name = strval(pathinfo($image, PATHINFO_FILENAME)); |
| 305 | 305 | } catch (Exception $e) { |
| 306 | - $name = rand(100,999) . '-' . Str::replace('.', '', strval(microtime(true))); |
|
| 306 | + $name = rand(100, 999).'-'.Str::replace('.', '', strval(microtime(true))); |
|
| 307 | 307 | |
| 308 | 308 | if ($this->dev) { |
| 309 | - Log::info('ConvertImage. Error get image name: ' . $image); |
|
| 309 | + Log::info('ConvertImage. Error get image name: '.$image); |
|
| 310 | 310 | Log::info($e->getMessage()); |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -345,10 +345,10 @@ discard block |
||
| 345 | 345 | return true; |
| 346 | 346 | } catch (Exception $e) { |
| 347 | 347 | try { |
| 348 | - unlink(public_path() . $source); |
|
| 348 | + unlink(public_path().$source); |
|
| 349 | 349 | return true; |
| 350 | 350 | } catch (Exception $e) { |
| 351 | - Log::info('ConvertImage. Error DELETE original image:' . $source); |
|
| 351 | + Log::info('ConvertImage. Error DELETE original image:'.$source); |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -367,24 +367,24 @@ discard block |
||
| 367 | 367 | { |
| 368 | 368 | if (!extension_loaded('gd')) |
| 369 | 369 | { |
| 370 | - Log::info('ConvertImage. PHP extension GD missed, image not converted: ' . $source); |
|
| 370 | + Log::info('ConvertImage. PHP extension GD missed, image not converted: '.$source); |
|
| 371 | 371 | return false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $dir = strval(pathinfo($source, PATHINFO_DIRNAME)); |
| 375 | - $name = strval(pathinfo($source, PATHINFO_FILENAME)) . '.' . $this->format; |
|
| 376 | - $destination = $dir . DIRECTORY_SEPARATOR . $name . '.webp'; |
|
| 375 | + $name = strval(pathinfo($source, PATHINFO_FILENAME)).'.'.$this->format; |
|
| 376 | + $destination = $dir.DIRECTORY_SEPARATOR.$name.'.webp'; |
|
| 377 | 377 | $info = getimagesize($source); |
| 378 | 378 | $isAlpha = false; |
| 379 | 379 | |
| 380 | - if ($info['mime'] == 'image/jpeg') |
|
| 380 | + if ($info[ 'mime' ] == 'image/jpeg') |
|
| 381 | 381 | $image = imagecreatefromjpeg($source); |
| 382 | - elseif ($isAlpha = $info['mime'] == 'image/gif') { |
|
| 382 | + elseif ($isAlpha = $info[ 'mime' ] == 'image/gif') { |
|
| 383 | 383 | $image = imagecreatefromgif($source); |
| 384 | - } elseif ($isAlpha = $info['mime'] == 'image/png') { |
|
| 384 | + } elseif ($isAlpha = $info[ 'mime' ] == 'image/png') { |
|
| 385 | 385 | $image = imagecreatefrompng($source); |
| 386 | 386 | } else { |
| 387 | - Log::info('ConvertImage. Not supported mime for convert webP: ' . $source); |
|
| 387 | + Log::info('ConvertImage. Not supported mime for convert webP: '.$source); |
|
| 388 | 388 | return false; |
| 389 | 389 | } |
| 390 | 390 | |
@@ -454,20 +454,20 @@ discard block |
||
| 454 | 454 | $imagePath = config('convert.dir'); |
| 455 | 455 | |
| 456 | 456 | if ($folder) { |
| 457 | - $imagePath .= '/' . $folder; |
|
| 457 | + $imagePath .= '/'.$folder; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // Замена двух слешей на один |
| 461 | 461 | $imagePath = Str::replace('//', '/', $imagePath); |
| 462 | 462 | |
| 463 | - if (!is_dir(public_path() . $imagePath)) { |
|
| 463 | + if (!is_dir(public_path().$imagePath)) { |
|
| 464 | 464 | try { |
| 465 | - mkdir(public_path() . $imagePath, config('convert.dir_permission'), config('convert.dir_recursive')); |
|
| 465 | + mkdir(public_path().$imagePath, config('convert.dir_permission'), config('convert.dir_recursive')); |
|
| 466 | 466 | if ($this->dev) { |
| 467 | - Log::info('ConvertImage. Create folder for convert image: ' . $imagePath); |
|
| 467 | + Log::info('ConvertImage. Create folder for convert image: '.$imagePath); |
|
| 468 | 468 | } |
| 469 | 469 | } catch (Exception $e) { |
| 470 | - Log::critical('ConvertImage. ERROR: Can not create folder: ' . $imagePath); |
|
| 470 | + Log::critical('ConvertImage. ERROR: Can not create folder: '.$imagePath); |
|
| 471 | 471 | $imagePath = config('convert.dir_temp'); |
| 472 | 472 | } |
| 473 | 473 | } |
@@ -496,21 +496,21 @@ discard block |
||
| 496 | 496 | if ($getFile->successful()) { |
| 497 | 497 | $file = $getFile->body(); |
| 498 | 498 | } else { |
| 499 | - Log::info('ConvertImage. Image HTTP read error: ' . $link); |
|
| 499 | + Log::info('ConvertImage. Image HTTP read error: '.$link); |
|
| 500 | 500 | return false; |
| 501 | 501 | } |
| 502 | 502 | } catch (Exception $e) { |
| 503 | - Log::info('ConvertImage. Error HTTP get image: ' . $link); |
|
| 503 | + Log::info('ConvertImage. Error HTTP get image: '.$link); |
|
| 504 | 504 | Log::info($e->getMessage()); |
| 505 | 505 | return false; |
| 506 | 506 | } |
| 507 | 507 | } else { |
| 508 | - $imageLink = Str::replace('//', '/', public_path() . '/' . $link); |
|
| 508 | + $imageLink = Str::replace('//', '/', public_path().'/'.$link); |
|
| 509 | 509 | |
| 510 | 510 | try { |
| 511 | 511 | $file = file_get_contents($imageLink); |
| 512 | 512 | } catch (Exception $e) { |
| 513 | - Log::info('ConvertImage. Image read (local) error: ' . $link); |
|
| 513 | + Log::info('ConvertImage. Image read (local) error: '.$link); |
|
| 514 | 514 | Log::info($e->getMessage()); |
| 515 | 515 | return false; |
| 516 | 516 | } |
@@ -528,14 +528,14 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | protected function getNewName(string $path, string $name): string |
| 530 | 530 | { |
| 531 | - $link = $path . '/' . $name . '.' . $this->format; |
|
| 531 | + $link = $path.'/'.$name.'.'.$this->format; |
|
| 532 | 532 | |
| 533 | - if (file_exists(public_path() . '/' . $link)) |
|
| 533 | + if (file_exists(public_path().'/'.$link)) |
|
| 534 | 534 | { |
| 535 | 535 | if ($this->overwrite) |
| 536 | 536 | { |
| 537 | 537 | // файл есть, разрешена перезапись и права на перезапись есть |
| 538 | - if(is_writable(public_path() . '/' . $link)) |
|
| 538 | + if (is_writable(public_path().'/'.$link)) |
|
| 539 | 539 | { |
| 540 | 540 | return $link; |
| 541 | 541 | } |
@@ -543,9 +543,9 @@ discard block |
||
| 543 | 543 | |
| 544 | 544 | // Файл есть, перезапись не разрешена или нет прав. |
| 545 | 545 | // Меняем имя файла |
| 546 | - Log::info('ConvertImage. Change name for overwrite: ' . $link); |
|
| 547 | - $newName = $name . '-' . Str::replace('.', '', strval(microtime(true))); |
|
| 548 | - $link = $path . '/' . $newName . '.' . $this->format; |
|
| 546 | + Log::info('ConvertImage. Change name for overwrite: '.$link); |
|
| 547 | + $newName = $name.'-'.Str::replace('.', '', strval(microtime(true))); |
|
| 548 | + $link = $path.'/'.$newName.'.'.$this->format; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |