【问题标题】:Function to get the original size of a featured image - full size获取特色图像原始尺寸的功能 - 全尺寸
【发布时间】:2020-04-19 02:17:19
【问题描述】:

我需要知道上传图片的原始尺寸。

我尝试了get_option( 'thumbnail_size_w' )get_option( 'thumbnail_size_h' ),我得到了 150x150,但无法找到获取此图像的原始大小而不是缩略图的方法。

我正在搜索类似 get_option( 'full_size_w' )get_option( 'full_size_h' ) 的内容,但它不起作用。

【问题讨论】:

    标签: wordpress function size thumbnails custom-post-type


    【解决方案1】:

    您可以检索大小为“完整”的图像源。 'source' 数组包含检索到的图像大小的维度。

    $src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    var_dump($src[1]); // image width
    var_dump($src[2]); // image height
    

    更多信息请参见https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

    【讨论】:

    • 这很完美,@jrswgtr ...而且很容易理解。谢谢!
    • @Tamplix 不客气!您会考虑投票并将答案标记为正确吗?提前谢谢你。
    【解决方案2】:
    the_post_thumbnail('full');         // Original image
    

    您可以使用 WordPress 的核心功能来获取不同大小的图像。

    the_post_thumbnail('thumbnail');    // Thumbnail (default 150px x 150px max)
    the_post_thumbnail('medium');       // Medium  (default 300px x 300px max)
    the_post_thumbnail('medium_large'); // Medium Large (default 768px x 0( automatic height by ratio) max ) since WP version 4.4
    the_post_thumbnail('large');        // Large (default 640px x 640px max)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-04
      • 1970-01-01
      • 2013-04-17
      • 2019-02-02
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      相关资源
      最近更新 更多