admin管理员组文章数量:1332353
I want to get the original image with the same width and height as uploaded.
My original image is 630*370.
Using the following function call I get a thumbnail sized at 630*198.
wp_get_attachment_image_src($PriImgId,array('630','370'));
How can I get it at 630*370
I want to get the original image with the same width and height as uploaded.
My original image is 630*370.
Using the following function call I get a thumbnail sized at 630*198.
wp_get_attachment_image_src($PriImgId,array('630','370'));
How can I get it at 630*370
Share Improve this question edited May 13, 2013 at 13:33 user26728 asked Jun 23, 2011 at 6:06 GowriGowri 8614 gold badges19 silver badges37 bronze badges3 Answers
Reset to default 46Try this :
wp_get_attachment_image_src( $PriImgId, 'full' );
Also, for more options see the Codex.
There's wp_get_attachment_image_url introduced in WordPress 4.4.0. It takes these arguments:
- int $attachment_id - Image attachment ID.
- string|array $size - Optional. Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'thumbnail'.
- bool $icon - Optional. Whether the image should be treated as an icon. Default false.
Returns string
(full attachment URL including domain) or false
if no image was found.
Example uses:
$thumbnail = wp_get_attachment_image_url( $attachmentId, 'my-custom-size' );
$original = wp_get_attachment_image_url( $attachmentId, 'full' );
$square = wp_get_attachment_image_url( $attachmentId, [600, 600] );
Image sizes are usually defined in functions.php of your theme. WordPress documentation covers this in depth: Post Thumbnails / Thumbnail Sizes
If an array of two numbers (width and height) is passed into the function, it tries to find the closets matching size while preserving the aspect ratio.
Under the hood it uses image_get_intermediate_size to find the preferred size.
I think you need to remove the quotes on '630' and '370'.
Try this:
wp_get_attachment_image_src($PriImgId,array( 630, 370 ) );
本文标签: attachmentshow to get original image using wpgetattachmentimagesrc
版权声明:本文标题:attachments - how to get original image using wp_get_attachment_image_src 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742321963a2452968.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论