Adding image sizes to image
@awaredigital probably the best solution would be to follow the suggestion to listen up to src changes, then find the right asset and update attributes accordingly
Read full answer below ↓Question
When I add an image attribute to the page I noticed that inside of the component the image has attributes to it. When I call my images into the asset manager I do it like the following: However, the height and width aren't available when the image gets added to the canvas. I've tried to get the sizes by doing: component.views[0].el.height and adding it to the object, but every time I try I get 0 because the image isn't available in the DOM yet, so it doesn't know what size it is. Is there a way to pass these heights and widths to the image, I need this for some lazy load functions I'm doing....
Answers (3)
@awaredigital probably the best solution would be to follow the suggestion to listen up to src changes, then find the right asset and update attributes accordingly
Hi @awaredigital checkout #2696 comment which is updating the styles whenever the src changes.
Cheers!
Hi @pouyamiralayi, thanks for the answer but that isn't what I'm looking to do. I'm looking to add height and width to the image element itself. So for example at the moment, the image goes in like this: <img src="http://placehold.it/350x250/459ba8/fff/image2.jpg" id="123" /> What I want to do is i...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #957
[Question] Add custom attributes (data-) to assets/images on Upload/Selection
Hi, I am trying my best to find the proper/best way to do this, but I need to attach two custom HTML5 data tags to an image once it is sele...
Issue #3685
showStylesOnChange is not working
Guys, I am new to grapes, I would like on component change show the Style Manager, here is my component and how I add it, also I would like...
Issue #930
[Question] Update resizer after asset changed
Hi! I trying to change default assets manager with ours custom manager. On double click the selected image is replaced with a new one with...
Issue #3216
FEAT: Add referrerPolicy to image loading through asset manager
What are you trying to add to GrapesJS? I'm trying to add the Referer header to image loading through asset manager. Describe your feature...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.