指定PHP文件调用的图像宽度和高度



我正试图找出在哪里指定facebook.png的图像大小,即24x24。

下面是代码,但我不确定如何指定大小。我知道如何在HTML中做到这一点,但在PHP中不知道。

<?php if ( get_option('solostream_facebook_url') ) { ?>
    <a title="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" rel="external" href="http://www.facebook.com/<?php echo stripslashes(get_option('solostream_facebook_url')); ?>"><img class="facebook-sub" src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" align="top" /></a>
<?php } ?>

heightwidth属性添加到<img>。检查以下代码。

<?php if ( get_option( 'solostream_facebook_url') ) { ?>
<a title="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" rel="external" href="http://www.facebook.com/<?php echo stripslashes(get_option('solostream_facebook_url')); ?>"><img class="facebook-sub" src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" align="top" height="24" width="24"/></a>
<?php } ?>

您想让PHP检索宽度/高度吗?

如果是,getimagesize()功能将执行以下操作:

<?php if ( get_option('solostream_facebook_url') ) { ?>
    list($width, $height, $type, $dims) = getimagesize("bloginfo('template_directory')/images/facebook.png");
    <a title="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" rel="external" href="http://www.facebook.com/<?php echo stripslashes(get_option('solostream_facebook_url')); ?>"><img $dims class="facebook-sub" src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" align="top" /></a>
<?php } ?>

最新更新