调整图像的宽度和高度

调整图像的宽度和高度

本文介绍了调整图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的内容存储在mysql中,如下所示:





< table width =210cellspacing =1cellpadding =1border =0> 
< tbody>
< tr>
< td>< img width =513height =680align =leftalt =src =/ userfiles / image / pic.jpg/>< / td>
< td>< img width =315height =700align =leftalt =src =/ userfiles / image / DSC_0389.JPG/>< / td>
< td>< img width =580height =320align =leftalt =src =/ userfiles / image / ktxh.jpg/>< / td>
< / tr>
< / tbody>
< / table>







当我从中加载时db,PHP和PHP在html中显示,没有问题。 

从mysql($ child_article [6])读取的$ content并通过动态代码以html显示:

$ sql_article =select * from articles approved = 1个按时间顺序DESC的顺序; @ $ childResult_article = general_query($ sql_article);
if($ child_article = mysql_fetch_row($ childResult_article))
echo decode_data($ child_article [6])。


现在,我想要所有图像,以固定的宽度和高度显示为200 X 200 AND TABLE BORDER ='0'(通过php从mysql加载$ content并替换宽度和高度所有图像按200 x 200然后回显$ content到网站)





我尝试过:



我试过,但不能结果:

$ newWidth = 200;
$ newHeight = 200;
$ content = preg_replace(array('/ width =\d +/ i','/ height =\d +/ i'),array(sprintf('width =%d' ,$ newWidth),sprintf('height =%d',$ newHeight)),$ child_article [6]);







我如何解决这个问题?
解决方案




I have content stored in mysql, as following: 



<table width="210" cellspacing="1" cellpadding="1" border="0">
    <tbody>
        <tr>
            <td><img width="513" height="680" align="left" alt="" src="/userfiles/image/pic.jpg" /></td>
            <td><img width="315" height="700" align="left" alt="" src="/userfiles/image/DSC_0389.JPG" /></td>
            <td><img width="580" height="320" align="left" alt="" src="/userfiles/image/ktxh.jpg" /></td>
        </tr>
    </tbody>
</table>




When I load from db, PHP and display in html by PHP, there is no problem.

The $content it be read from mysql($child_article[6]) and display in html by dynamic code:

$sql_article = "select * from articles where approved=1 order by timestamp DESC"; @$childResult_article = general_query($sql_article);
if ($child_article = mysql_fetch_row($childResult_article))
echo decode_data($child_article[6]).


Now, I want all images, be displayed by fixed width and height as 200 X 200 AND TABLE BORDER = '0' ($content load from mysql by php and replace width and height of all images by 200 x 200 then echo $content to website)



What I have tried:

i tried, but can't result:

$newWidth = 200;
$newHeight = 200;
$content = preg_replace( array('/width="\d+"/i', '/height="\d+"/i'), array(sprintf('width="%d"', $newWidth), sprintf('height="%d"', $newHeight)), $child_article[6]); 




How do I solve this problem?
解决方案




这篇关于调整图像的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 06:53