traderinteractive /
image-util-php
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | require_once __DIR__ . '/vendor/autoload.php'; |
||
| 4 | |||
| 5 | use TraderInteractive\Util\Image; |
||
| 6 | |||
| 7 | $files = glob(__DIR__ . '/image-tests/*.jpg'); |
||
| 8 | |||
| 9 | $thumbnails = [ |
||
| 10 | ['width' => 1024, 'height' => 768, 'quality' => 70, 'bestfit' => true, 'upsize' => true, 'blurBackground' => true, 'blurValue' => 100.0], |
||
| 11 | ['width' => 96, 'height' => 72, 'quality' => 60, 'bestfit' => true, 'upsize' => true, 'blurBackground' => true, 'blurValue' => 100.0], |
||
| 12 | ['width' => 512, 'height' => 384, 'quality' => 60, 'bestfit' => true, 'upsize' => true, 'blurBackground' => true, 'blurValue' => 100.0], |
||
| 13 | ['width' => 180, 'height' => 135, 'bestfit' => true, 'upsize' => true, 'blurBackground' => true, 'blurValue' => 100.0], |
||
| 14 | ]; |
||
| 15 | |||
| 16 | foreach ($files as $file) { |
||
| 17 | $imagick = new Imagick(); |
||
| 18 | $imagick->readImage($file); |
||
| 19 | |||
| 20 | $basename = pathinfo($file, PATHINFO_FILENAME); |
||
| 21 | |||
| 22 | $outputDirectory = dirname($file) . "/output/{$basename}"; |
||
| 23 | @mkdir($outputDirectory, 0755, true); |
||
|
0 ignored issues
–
show
|
|||
| 24 | |||
| 25 | foreach ($thumbnails as $thumbnail) { |
||
| 26 | $boxWidth = $thumbnail['width']; |
||
| 27 | $boxHeight = $thumbnail['height']; |
||
| 28 | $resized = Image::resize($imagick, $boxWidth, $boxHeight, $thumbnail); |
||
| 29 | $resized->writeImage("{$outputDirectory}/resized-{$boxWidth}x{$boxHeight}.jpg"); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 |
If you suppress an error, we recommend checking for the error condition explicitly: