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
[RTM] Image and Picture as services #342
Conversation
To tell you my opinion on the basic questions:
Regarding the Also, we should use a compiler pass to automatically detect the available Imagine options and choose the best (= only fallback to GD2 if Imagick is not supported). |
Thinking about this, I think a general |
For the image service we would have to inject three models: |
Just think about Doctrine. Each entity has it's repository… |
but only one entity manager ;) |
But I can inject |
👍 |
True! It just means we will improve our model stuff while we actually wanted to prefer Doctrine ^^ |
Like so aaf12ec? |
Where should we put the code for |
Can I start working on it with the class structure described above? |
I would love to discuss the topic on today's Contao call. The compiler pass looks pretty good. |
I will be there. |
I added some classes :) The current proposal would work like this:
@contao/developers what do you think? |
|
||
try { | ||
new $class(); | ||
break; |
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 just realized this can be simplified a lot. Simply return $class
here, then you also don't need the if-condition below (just throw the exception).
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.
Done.
I think I like the basic approach :-) The only thing I would change to bring even more interoperability would be to use things like |
@Toflar thanks. I agree we should add some interfaces, but I would like to get a working implementation and then adding the interfaces, to better understand which interfaces could be useful. |
$relative = false | ||
) { | ||
$this->size = $size; | ||
$this->relative = (bool) $relative; |
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.
What is a relative image dimension?
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.
For images with a ratio, but no absolute size. E.g. a SVG image with width="100%" height="100%"
.
See the difference between File->imageSize
and File->imageViewSize
in contao/core#7882.
I also like the approach in general. I just wonder if the |
You suggest to add
Where should we put the code for that than? |
Now that the adapters are finally merged, I think we can continue with that? |
This should be ready for comments now :) One thing I’d like to discuss before merging is, what should be the Symfony-way alternative to the image hooks Note to myself: After this gets merged I should take a look at some other image related feature requests:
|
Conflicts: src/Resources/contao/dca/tl_settings.php
This reverts commit 386fe86. Conflicts: src/Image/ImageFactory.php src/Image/PictureFactory.php tests/Image/ImageFactoryTest.php tests/Image/PictureFactoryTest.php
public function process(ContainerBuilder $container) | ||
{ | ||
$container->setParameter( | ||
'contao.root_dir', |
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 code does not what the phpDoc comment says. Also, we should not add a contao.root_dir
parameter.
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.
We need a way to inject "%contao.root_dir%/%contao.image.target_path%"
into the resizer service. Should I use the %kernel.root_dir%
instead?
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 is not so easy. I have created a working implementation, but I need to discuss this with you on Mumble.
Merged in 9b6694f. |
This is a very early draft of the image handling as a service. Here are my ideas:
The new classes
Contao\CoreBundle\Image\Image
andContao\CoreBundle\Image\Picture
work similar to the current classes, but with dependency injection and without thecreate
and legacy methods. The newImage
class usesImagine
to manipulate image data. The Image and Picture objects are created via a factory which is registered in the service container.The old classes
Contao\Image
andContao\Picture
are wrappers around the new classes and services to keep backwards compatibility.Does that make sense?
Questions
executeResize
andgetImage
? To be 100% backwards compatible we would have to pass an instance of theContao\Image
class.Contao\File
class?ImageFactory
andPictureFactory
orFactory
withcreateImage
andcreatePicture
methods?contao.image.cache
service?imagine_class
configuration node the right way to make the used Imagine class configurable?contao.adapter.model_repository
service to get access to the files and image size models.