Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从wordpress中的图像获取高度和宽度_Javascript_Php_Html_Wordpress - Fatal编程技术网

Javascript 从wordpress中的图像获取高度和宽度

Javascript 从wordpress中的图像获取高度和宽度,javascript,php,html,wordpress,Javascript,Php,Html,Wordpress,我正在努力在我的WordPress网站上创建一个信息块。 我想得到照片的高度X宽度: get_the_post_thumbnail_url() 我想把它打印在页面上,比如: image size: 1234x123 1.2mb 我只是不知道怎么做。我在网上找到了很多不同的例子,但我总是会遇到不同的错误 希望有人能想出一个好办法来做到这一点。:) 此WP功能提供图像宽度和高度: 请在此阅读更多: 从文档中,它表示返回: 返回数组(url、宽度、高度、中间值)或false, 如果没有img。

我正在努力在我的WordPress网站上创建一个信息块。 我想得到照片的高度X宽度:

get_the_post_thumbnail_url() 
我想把它打印在页面上,比如:

image size: 1234x123 1.2mb
我只是不知道怎么做。我在网上找到了很多不同的例子,但我总是会遇到不同的错误


希望有人能想出一个好办法来做到这一点。:)

此WP功能提供图像宽度和高度:

请在此阅读更多:

从文档中,它表示返回:

返回数组(url、宽度、高度、中间值)或false, 如果没有img。

例如:

  $img = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), "full" );
现在


此WP功能提供图像宽度和高度:

请在此阅读更多:

从文档中,它表示返回:

返回数组(url、宽度、高度、中间值)或false, 如果没有img。

例如:

  $img = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), "full" );
现在

试一试


然后呼出大小

<?php
    echo $size;
?>

从文档中获取

尝试

<?php
    $size = getimagesize(get_the_post_thumbnail_url());
?>

然后呼出大小

<?php
    echo $size;
?>

摘自文档

您可以尝试以下代码

            if ( has_post_thumbnail() ) {
                    //thumbnail
                    echo  get_the_post_thumbnail(get_the_ID(),"thumbnail"); //thumbnail,medium,large,full,array(1234,123)
                    //medium
                    echo  get_the_post_thumbnail(get_the_ID(),"medium");
                    //large
                    echo  get_the_post_thumbnail(get_the_ID(),"large"); 
                    //full
                    echo  get_the_post_thumbnail(get_the_ID(),"full"); 
                    //fixed size image(width, height)
                    echo  get_the_post_thumbnail(get_the_ID(),array(1234,123)); 

                }
你可以试试下面的代码

            if ( has_post_thumbnail() ) {
                    //thumbnail
                    echo  get_the_post_thumbnail(get_the_ID(),"thumbnail"); //thumbnail,medium,large,full,array(1234,123)
                    //medium
                    echo  get_the_post_thumbnail(get_the_ID(),"medium");
                    //large
                    echo  get_the_post_thumbnail(get_the_ID(),"large"); 
                    //full
                    echo  get_the_post_thumbnail(get_the_ID(),"full"); 
                    //fixed size image(width, height)
                    echo  get_the_post_thumbnail(get_the_ID(),array(1234,123)); 

                }

我想您可以使用jquery选择图像,并打印属性?或者使用纯Javascript我想您可以使用jquery选择图像,打印属性?或者使用纯javascriptI我想他想要的是自然的高度和宽度,而不是主题的“完整”大小?@Stender“完整”表示图像的自然宽度和高度,而不是特定主题的大小。i、 e._post_缩略图('full');//原始图像分辨率(未修改)src:@LinusKarlsson太棒了!快乐编码!:)@斯坦德:我的荣幸:)谢谢你@mohsin这只适用于循环中的第一幅图像,而不是每幅图像。我认为他想要的是自然高度和宽度,而不是主题的“完整”大小?@Stender“完整”表示图像的自然宽度和高度,而不是特定主题的大小。i、 e._post_缩略图('full');//原始图像分辨率(未修改)src:@LinusKarlsson太棒了!快乐编码!:)@斯坦德:我的荣幸:)谢谢你@mohsin这只适用于循环中的第一个映像,而不适用于每个映像。我收到了以下错误:警告:getimagesize():无法打开流:HTTP请求失败!HTTP/1.1 404未在书中找到,就像我太晚了一样,此错误是由于正在服务的url中没有HTTP://导致的。我收到此错误,然后:警告:getimagesize():未能打开流:HTTP请求失败!HTTP/1.1 404未在页面中找到,就像我太晚了一样,此错误是由于正在提供服务的url中没有HTTP://导致的