简体   繁体   中英

Get image height and width into Data size PHP

I am using this code in my webpage. I use Data-size attribute for maintaining the aspect ratio of the image while pop-up.

<figure>
          <a href="img/large-image/1.jpg" itemprop="contentUrl"  data-size="1024x1024">
              <img src="img/small-thumbnail/1.jpg" itemprop="thumbnail" alt="Image description" />
          </a>
          <figcaption itemprop="caption description">Image caption 1</figcaption>
        </figure>
<figure>
          <a href="img/large-image/2.jpg" itemprop="contentUrl" data-size="964x1024">
              <img src="img/small-thumbnail/2.jpg" itemprop="thumbnail" alt="Image description" />
          </a>
          <figcaption itemprop="caption description">Image caption 2</figcaption>
        </figure>

<figure>
          <a href="img/large-image/3.jpg" data-size="683x683">
              <img src="img/small-thumbnail/3.jpg" itemprop="thumbnail" alt="Image description" />
          </a>
          <figcaption itemprop="caption description">Image caption 3</figcaption>
        </figure>

Now I can't enter every time the image dimensions manually. so, How can I automatically put the image width and height value into the "data-size" attribute?

getimagesize() can be used for getting image dimensions:

<?php
    list($width, $height) = getimagesize("img/large-image/1.jpg");
?>

<a href="img/large-image/1.jpg" itemprop="contentUrl"  data-size="<?php echo $width . 'x' . $height; ?>">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM