-
-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added scale and resizeProportionally methods. #227
Conversation
src/claviska/SimpleImage.php
Outdated
|
||
// fill background, then place centered resized image | ||
$newImage = imagecreatetruecolor($width, $height); | ||
fwrite(STDERR, "test: " . $color['red'] . " " . $color['green'] . " " . $color['blue'] . " " . $color['alpha']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed.
src/claviska/SimpleImage.php
Outdated
$height = $width; | ||
|
||
$aspectRatio = $width / $height; | ||
if($aspectRatio > $this->getAspectRatio()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional formatting is inconsitent. Please use brackets :)
src/claviska/SimpleImage.php
Outdated
$color = imagecolorallocatealpha( | ||
$newImage, $color['red'], $color['green'], $color['blue'], 127 - $color['alpha']*127 | ||
); | ||
imagefill($newImage, 0, 0, $color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'd be better off creating a new SimpleImage instance and using overlay()
instead of using raw image functions.
Thanks for the thorough PR! I marked up a couple things I noticed in the code. The I really think creating a new SimpleImage instance and using $newImage
->fromNew($width, $height, $color)
->overlay($originalImage); The |
src/claviska/SimpleImage.php
Outdated
} | ||
|
||
// | ||
// Resize an image to tightly fit a rectangular of the specified dimensions, without deformation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"rectangular" and "centred" typo
Hello! I've did some requested changes. I do not change requestProportionally implementations as this is working – I have tested transparent img on transparent bg, nontransparent on transparent and transparent on nontransparent. You can verify with example/index_mod.php. |
The point is to eliminate duplicate code, especially code that’s prone to edge cases. Transparent images in GD are a pain. The overlay method is a battle-tested way to merge two images. In its current state, when new edge cases come up, we’ll need to fix them in multiple methods. This means extra work and leaves room for error. By using existing methods, we’ll only have to fix those types of things once. 😄 |
Closing this due to lack of activity. |
I know, there is snippet
$image->resize($image->getWidth() * .5)
to mimic scale function, but it would be convenient to have some method with semantic.Also added resizeProportionally method, which is somehow similar to bestFit, but final image have always specified dimensions with some background color.