Skip Navigation

[Resolved] Get height and with of image

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to get their image dimensions from the url.

Solution:
Take a look here for the exact solution.
https://toolset.com/forums/topic/get-height-and-with-of-image/#post-1238794

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by sachaB 5 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1238731

Tell us what you are trying to do?
I need to insert as data attribute the image size, like this:

Which has the size in the data-sizte attribute

Is there any documentation that you are following?
I looked in the forums and here
https://toolset.com/documentation/customizing-sites-using-php/functions/#image
But with no result

Is there a similar example that we can see?
I'm using the Photoswipe library hidden link

What is the link to your site?
hidden link

Thanks

#1238792

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Sacha,

Thank you for contacting our support forum.

Actually we are not able to get the image size itself since we are just getting the image only. To get the image size you would need to write some custom code in order to get the image dimensions.

Thanks,
Shane

#1238794

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Sacha,

This shortcode should be able to do the trick.


// Add Shortcode
function get_image_dimensions( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'url' => '',
		),
		$atts
	);

	list($width, $height, $type, $attr) = getimagesize($atts['url']); 
	
	return $width."*".$height;

}
add_shortcode( 'get_image_dimensions', 'get_image_dimensions' );

Add it to the Toolset custom code in Toolset -> Settings -> Custom Code and add the snippet and activate it.

You can use the shortcode like this [get_image_dimensions url="url to image"]

Please let me know if this helps.
Thanks,
Shane

#1239812

My issue is resolved now. Thank you!