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
Missing image constructor with file path in 2.x #2627
Comments
Direct instantiation of The functionality you're after has been preserved though, after reviewing the docs I think this could be made clearer, but you're after This is also available in twig templates, so where you used to do Highly recommend reviewing the upgrade guide a couple times - https://timber.github.io/docs/v2/upgrade-guides/2.0/#timber\image-and-timber\attachment - It's taken a few read-throughs for the implications to really sink in for me personally! Hope this helps. |
The behavior is not the same. That only works for attachments: images that have been uploaded to WordPress via the media manager. But what I'm expecting is to be able to use Timber Image class for arbitrary images, maybe part of the theme. https://github.com/timber/timber/blob/2.x/src/Timber.php#L615 But in timber 1, you could create Image objects based on arbitrary paths, and then use image manipulation functions with them. |
Right, I can see this, and appreciate the nuance there - but I believe that the intention behind classes like Attachment is exactly that, to mirror a WP_Post backed object. Looking at the implementation in 1.x, If your main concern is resizing or other operations like this, are you aware they do not need to receive a If you have the abspath OR an external URL, you can pass this into the Other operations in the Image Helper class can be called directly or accessed via the twig filters or their PHP static functions without a While I understand that it means some changes to existing code, 2.0 is definitely going to need that across the board - the whole API is being tightened so it can be better maintained, and this involves the team rolling back a lot of "grey areas" where the use over time has made it really hard to make meaningful changes to Timber. Using a class like Don't take my word as gospel - definitely up to the core team to decide what's right here, but based on what I've laid out above, I think it makes sense for this not to be supported anymore. |
I completely agree with you on a few things there. But a few points
That's why I think this is a clear gap in 2.0. Not sure if the gap is functionality is missing (that was my guess), or deprecation documentation is missing (that's another option), but "everything is as expected" is clearly not what I see here 😅 |
Absolutely - totally agree with you that if this is how it's going to be then the docs and deprecation notices need to be improved. In 1.x When dealing with Image manipulation, the main benefit I can see is that you don't need to treat external / theme provided images differently in your templates, and they can be agnostic to the "source" of the original image, even though in these cases really all the There's a few potential ways forward here, might need some input from @jarednova / @gchtr - allow this in |
Thanks @xavivars and @aj-adl for flagging this and thinking it through. This is really some shortcoming of the current image functionality. This particular functionality is still missing in 2.x. That’s why it also isn’t documented yet. We thought about the concept of images from external URLs when the introduced the The relevant discussion can be found here: We thought of a new Basically what @aj-adl proposes:
I didn’t look into what exactly is needed to make this work. If any of you feels like they could implement this, we would appreciate the help. |
I'll take this. However, I'm wondering if I should add another method (like I'll take the first approach for now, but happy to change it later. |
A possible solution for this has been implemented in #2639 |
Thank you! You did most of the work |
Expected behavior
Can create an image from a URL or local path
$myImage = new Image( get_stylesheet_directory() . '/img/compass.png' );
Actual behavior
Constructor for images based on path no longer exists
Steps to reproduce behavior
What version of WordPress, PHP and Timber are you using?
PHP 7.4, WordPress 6.0, Timber 2.x beta 1
More information
Images used to have an
init
method that was called from the image constructor.https://github.com/timber/timber/blob/master/lib/Image.php#L265
All the underlying code is still there (now in
Attachment
class), but it's protected and can't be directly used:https://github.com/timber/timber/blob/2.x/src/Attachment.php#L129
The text was updated successfully, but these errors were encountered: