-
Notifications
You must be signed in to change notification settings - Fork 166
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
How to scale images in a controller #35
Comments
You can get ahold of Imagine service by calling $container->get('imagine'); once you have it, http://imagine.readthedocs.org/en/latest/index.html will help you with how to use it |
thanks very much! |
Since I just implemented this last night in JmikolaImagineBundle, I'd suggest something like: <?php
$box = $image->getSize();
$resizedImage = $image->resize($box->scale(1.5)); That would scale an image by its own dimensions (probably what you want). |
may I reiterate: <?php
$image->resize($image->getSize()->scale(1.5)); |
@avalanche123: I guess you don't care about Law of Demeter anymore :) |
@jmikola, do care :) here we're dealing with <?php
$a = new A();
$a->b()->c(); // would be terrible as you'd have to mock the whole chain in tests while in our case we'd do something like: <?php
$size = new Box(100, 100);
// stub out initial size
$image->expects($this->once())
->method('getSize')
->will($this->returnValue($size))
;
$image->expects($this->once())
->method('resize')
->with(new Box(150, 150))
;
// our filter that executes my above code
$filter->apply($image); As you can see, mocking value objects is unnecessary as they are easy to construct and have on dependencies on other objects (easy to construct and have no dependencies is pretty much the same thing). Another example would be PHP's To conclude, don't violate the LOD for service objects, while don't bother with it in cases where object operates on its internal state. For example, builder's fluent interface, but not the factory method... Cheers! :) |
just realized, that the example is talking about and applicable to 'newables' in general and not only value objects you can read about 'newables' at http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/ |
Extracted the abstract class Resolver from WebPathResolver
Found no documentation about that. Could you add it?
Best regards
Stephan
The text was updated successfully, but these errors were encountered: