Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to output a image in a pre-determined size (Ie; using add_image_size) using just the img tag?

For example, how can I make sure that the image that is echoed using this tag is the exact size I determined in functions.php under 'slider'

<img src="<?php echo of_get_option('slideshow_1');?>" alt="#"/>

I hope that made some sort of sense.

share|improve this question
4  
Try get_image_tag/(). –  kaiser Oct 8 '12 at 17:42
    
@kaiser as an answer! –  Rarst Oct 9 '12 at 0:27
    
@Rarst Will do, when I'm sure I understood the question right. 100% accept rate tells me that the OP will follow up. –  kaiser Oct 9 '12 at 0:53
add comment

1 Answer

How about PHP Function getimagesize()

<?
$sImageurl = of_get_option('slideshow_1');
list($iWidthinpx, $iHeightinpx) = getimagesize($sImageurl);
echo '<img 
    src="' . $sImageurl . '" 
    width="' . $iWidthinpx. '" 
    height="' . $iHeightinpx. '" 
    alt="#"/>';
?>

or if you know the attachment id instead of the attachment url you could use

<?
$aImagedata = wp_get_attachment_image_src($iAttachmentid, 'my-image-size', false);
list($sImageurl, $iWidthinpx, $iHeightinpx) = $aImagedata;
echo '<img 
    src="' . $sImageurl . '" 
    width="' . $iWidthinpx. '" 
    height="' . $iHeightinpx. '" 
    alt="#"/>';
?>

and if you don't know the $iAttachmentid you could use the following to get it
(taken from http://wordpress.org/support/topic/need-to-get-attachment-id-by-image-url):

global $wpdb;
$sImageurl = of_get_option('slideshow_1');
$sQuery = "SELECT ID FROM {$wpdb->posts} WHERE guid='$sImageurl'";
$iAttachmentid = $wpdb->get_var($sQuery );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.