aplus-framework / image

Aplus Framework Image Library
https://aplus-framework.com/packages/image
MIT License
216 stars 7 forks source link

chaining not implemented #1

Closed KarelWintersky closed 4 weeks ago

KarelWintersky commented 4 weeks ago
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Framework\Image\Image;

$filename = __DIR__ . '/test.jpg';

$image = new Image($filename);

$width = 200;
$height = 200;
$marginLeft = 100;
$marginTop = 100;

$i1 = $image->crop($width, $height, $marginLeft, $marginTop);
$i2 = $image->filter(IMG_FILTER_NEGATE);

$i1->save('test_crop.jpg');

$i2->save('test_negate.jpg');

Both images are cropped and negated.

natanfelles commented 4 weeks ago

It is ok. $i1 and $i2 have the same Image instance.

natanfelles commented 4 weeks ago

Hello, @KarelWintersky ! Thank you for using Aplus Framework!

The Image class implements a design called fluent interface.

To generate two different images you need to create two Image objects:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Framework\Image\Image;

$filename = __DIR__ . '/test.jpg';

$width = 200;
$height = 200;
$marginLeft = 100;
$marginTop = 100;

$i1 = new Image($filename);
$i1->crop($width, $height, $marginLeft, $marginTop)
   ->save('test_crop.jpg');

$i2 = new Image($filename);
$i2->filter(IMG_FILTER_NEGATE)
   ->save('test_negate.jpg');

I hope I could help you.

KarelWintersky commented 3 weeks ago

yes, i know that you can do that. i was hoping that the framework would implement the ability to process the same image object in different ways. unfortunately no framework (except mine) can do that.

https://github.com/php/php-src/issues/15636