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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器