Back to Top
The nuts and bolts for
Creative web development

How to dynamically get image dimensions with PHP

Question:
How to dynamically get image dimensions (image height and width) and use it in Advanced Layer Popup?

Answer:


If you use PHP for server-language, you can use the following code to get the dimensions of particular image:

<?php list($w, $h) = getimagesize("Images/Sunset.jpg") ?>

Then replace the with and height into parameters of the Advanced Layer javascript function with $w and $h values. For exmaple:

<a href="#" onclick="dmxAdvLayerPopup('Sunset','Images/Sunset.jpg','alpSunset','','OS_Look','center','center', <?php echo $w ?>, <?php echo $h?>, 0,true,false,false,0,'','Linear',2,true,'','Linear',2,true,'',1,5,true,false,'#FFFFFF');return document.MM_returnValue">Sunset</a>

Also, instead the static path and picture filename (Images/Sunset.jpg) you can use picture name and path from database.

Georgi Kralev

Georgi Kralev is a native of Bulgaria and graduated from Technical University Sofia with a Master’s Degree in Computer systems and technologies.

Starting his professional career as desktop developer at Delphi, he moved into the field of .NET development (ASP.NET, windows forms, console applications, windows services, and web services). He also has experience with the following technologies: classical ASP, PHP, HTML / DHTML, XML, JavaScript).

He has received the EUR ING professional title from the European Federation of National Engineering Associations (FEANI)

He has achieved the following professional certificates:
• Microsoft Certified Professional Developer (MCPD) Enterprise Application Developer and Microsoft Certified Professional.
• Several Brainbench certificates in software development.
• Cisco Certified Network Associate

Personal web site for C# and .NET programming:
http://gdkralev.googlepages.com

See All Postings From Georgi Kralev >>

Share this Article