Page 1 of 1
center an image in php
Posted: Thu Oct 01, 2009 8:55 pm
by podarum
Hi, I'm printing an image from an if statement, and I want to centre it.. any idea how.. so the last line in echo I'd like to centre it horizontally on the page.. Thanks
Code: Select all
{if ($Utilization2 == 0)
{echo "<table><td style=text-align:justify> Your utilization position is solid and not an issue with most credit grantors in this regard. The debt-to-credit ratio is <b>".$Utilization2;print " %</b>";print". You are not carrying a balance, but would want to show a higher utilization % to demonstrate that you use the credit assigned and able to pay it off. </td></table>";
echo'<img src="images/Process5 0a.png" width="350" height="200">';}
Re: center an image in php
Posted: Thu Oct 01, 2009 9:00 pm
by mybikeisgreen
Have you tried using <center><img src="..."></center>?
Re: center an image in php
Posted: Thu Oct 01, 2009 9:09 pm
by podarum
Yeah, tried that , it didn't work...
Re: center an image in php
Posted: Thu Oct 01, 2009 9:19 pm
by mybikeisgreen
Did you try
style=text-align:center
Re: center an image in php
Posted: Thu Oct 01, 2009 9:27 pm
by podarum
Yup, just tried that and all it did was center the text only but not the image...
Re: center an image in php
Posted: Thu Oct 01, 2009 9:29 pm
by mybikeisgreen
did you try
style="margin-left:auto;margin-right:auto;"
Re: center an image in php
Posted: Thu Oct 01, 2009 9:34 pm
by podarum
hehehe..yes, tried that and nothing happened
Re: center an image in php
Posted: Thu Oct 01, 2009 9:49 pm
by s.dot
Centering an image will only center it within the element it's contained in.
Try making your <td> with a width attribute like <td width="500">text<center><img></center></td>.
Re: center an image in php
Posted: Thu Oct 01, 2009 9:56 pm
by podarum
I tried tis and got error... is this what you meant?
Code: Select all
{if ($Utilization2 == 0)
{echo "<table> <td width="500">text<center><img></center></td> Your utilization position is solid and not an issue with most credit grantors in this regard. The debt-to-credit ratio is <b>".$Utilization2;print " %</b>";print". You are not carrying a balance, but would want to show a higher utilization % to demonstrate that you use the credit assigned and able to pay it off. </td></table>";
echo '<img src="images/Process5 0a.png" width="350" height="200">';}
Re: center an image in php
Posted: Fri Oct 02, 2009 1:32 am
by Griven
Remove that <center><img></center> bit.
Then use this at the end:
Code: Select all
echo '<div style="width: 100%; text-align: center"><img src="images/Process5 0a.png" width="350" height="200" /></div>';
Re: center an image in php
Posted: Fri Oct 02, 2009 11:00 am
by podarum
Thank you .. that worked...