Comments (7)
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
from avalancheimaginebundle.
thanks very much!
from avalancheimaginebundle.
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).
from avalancheimaginebundle.
may I reiterate:
<?php
$image->resize($image->getSize()->scale(1.5));
from avalancheimaginebundle.
@avalanche123: I guess you don't care about Law of Demeter anymore :)
from avalancheimaginebundle.
@jmikola, do care :) here we're dealing with Box
immutable value object (immutable and value object pretty much assumes each other). I feel that law of demeter makes a lot of sense when each method call is returning another object. so if we had A::b() -> B
and B::c() -> C
then
<?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 DateTime
class, it is globally accessible and easy to construct.
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! :)
from avalancheimaginebundle.
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/
from avalancheimaginebundle.
Related Issues (20)
- Using Chain and/or Paste Filters HOT 3
- Not working HOT 3
- Routing is not working for Symfony version 2.5
- Serving images on alternate URI
- RouteNotFoundException instead of NotFoundHttpException
- ImageMagick fails to open a JPG
- How to use filters other than 'my_thumb'? HOT 2
- Thumbnail of SVG files
- Incorrect permissions on cached images HOT 3
- 'source_root' in each filter does not override the global 'source_root' HOT 2
- CROP FILTER
- imagine blur symfony2
- Uncaught PHP Exception Imagine\Exception\InvalidArgumentException code 0
- Disabled Autorotate
- Mistake in clear cache in CachePathResolver
- Ephemeral storage solution
- worker queue image transformations
- How can I keep the size of an image in the cache, when I updated an image? HOT 1
- upgrade to Symfony 3
- apply_filter doesn't create image cache in symfony prod HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avalancheimaginebundle.