Define WordPress image size in img tag

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 );

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)