doudiemei2013 2017-04-06 12:52
浏览 92

使用php或javascript / jquery获取图像大小 - getimagesize失败

I'm using a really good lightbox script but it needs me to output the image sizes. The site I'm using is php and can resize images as they are uploaded. It does not store the images sizes in the database.

The code needs to be displayed as follows.

<a href="http://www.fullurl.com/image.jpg" data-original-url="http://www.fullurl.com/image.jpg" data-original-width="123" data-original-height="456">
    <img src="http://www.fullurl.com/thumbnail-image.jpg" alt="product name" />
</a>

I've tried using getimagesize but it only works on images that have not been resized by the system. I think they are missing some vital info as images that have uploaded but not resized work fine. There are currently about 1200 images already uploaded so redoing them is not an option.

My current method is using php as follows.

<?php
$image1 = 'http://www.fullurl.com/thumbnail-image.jpg';
list($width, $height) = getimagesize($image1);
 ?>

<a href="http://www.fullurl.com/image.jpg" data-original-url="http://www.fullurl.com/image.jpg" data-original-width="123" data-original-height="456">
    <img src="http://www.fullurl.com/thumbnail-image.jpg" alt="product name" />
</a>

If I use the following I get bool(false) as the output.

$path1 = 'http://www.fullurl.com/image.jpg';
$vals_arr1 = getimagesize($path1);
echo "<pre>";var_dump($vals_arr1);echo "</pre>";

I'm not a programmer. My question is how can I output the image info as below? I'm happy to try alternative php, jquery / javascript as is needed. Ideally it needs to be simple and fast.

<a href="http://www.fullurl.com/image.jpg" data-original-url="http://www.fullurl.com/image.jpg" data-original-width="123" data-original-height="456">
  • 写回答

2条回答 默认 最新

  • dongmei2957 2017-04-06 13:02
    关注

    This works

    $path1 = 'https://jpeg.org/images/jpeg-home.jpg';
    $vals_arr1 = getimagesize($path1);
    echo "<pre>";var_dump($vals_arr1);echo "</pre>";
    

    The bug must be somewhere else. Check the URLs! Are they valid? And check if allow_url_fopen is set to true on your server.

    Else this can help: https://stackoverflow.com/a/25231517/4916265

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么