Jump to content
Chris Falkenstein

Get width of specific image

Recommended Posts

Hi all,  I created a Hanna Code that allows a client to embed a image.  First they upload an image to the page (using the images field).  Then they use Hanna Code to embed it.  The Hanna Code looks like the following.

[[image file='myimage.jpg' caption="my image" align='center']]

I'd like to set a max-width on the generated HTML img tag.  I need the width of the image.  How can I get it?  So I need a way to get the image width based on the name of the image? Any ideas?   

 

Share this post


Link to post
Share on other sites

Under the "Input" tab for the field (in question), you can set the max width and/or max height for uploaded images. 

Screen Shot 2017-08-30 at 3.53.42 PM.png

However, if you are trying to output a max-width property for use with your hanna code, My "solution" might not be what you are looking for.

Share this post


Link to post
Share on other sites

Thanks for the response. 

I need the width so I can set the max-width css property of the img tag.  I need the value of the width.  Is there a Processwire method/function for that which I can use when coding my Hanna Code?

Share this post


Link to post
Share on other sites
$image = $page->images->get("name=myimage.jpg");
$image->width();

 

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...