Jump to content


Photo

Pictures in php


  • Please log in to reply
3 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 08 March 2006 - 02:19 PM

Hi,
i am trying to change the size of the pictures i want to display in php. The problem is that when i try and do it the picture simply dissapears. In html i used width=100 and height =100 as shown below and it worked:

<a href="simfreeMot.php"> <img src="Motorolla Logo.bmp" width=100 height=100></a>

I am using the code below to show the pic in php:

echo "<img src='{$products[$i]['phonepic']}'>";

This works however when i try and change the size using:

echo "<img src='{$products[$i]['phonepic']} width=100 height=100'>";

It comes up with no picture(as if there is a broken link to the picture. There is a blank page produced when i try:

echo "<img src='{$products[$i]['phonepic'] width=100 height=100}'>";

If you know how to do this properly please let me know.
Thanks.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 March 2006 - 02:26 PM

You almost had it with this code
<?php echo "<img src='{$products[$i]['phonepic']} width=100 height=100'>"; ?>

Try this (you had the terminating single quote in the wrong place)
<?php echo "<img src='{$products[$i]['phonepic']}' width=100 height=100>"; ?>
or
<?php echo '<img src="' .  $products[$i]['phonepic'] . '" width=100 height=100>'; ?>
In the above snippet, I interchanged the single and double quotes and using the string concatenation operator to form the final string.

Ken


#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 March 2006 - 02:59 PM

Bear in mind altering the height and width values of an image will simply distort them and in teh vast majority of cases this makes them look very poor - unprofessional even!

You can grab the size of the image on upload, or better still resample and create an image of the correct dimensions....

check out the gdlibrary for such magical trickery
follow me on twitter @PHPsycho

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 08 March 2006 - 03:21 PM

[!--quoteo(post=352858:date=Mar 8 2006, 09:26 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 8 2006, 09:26 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You almost had it with this code
<?php echo "<img src='{$products[$i]['phonepic']} width=100 height=100'>"; ?>

Try this (you had the terminating single quote in the wrong place)
<?php echo "<img src='{$products[$i]['phonepic']}' width=100 height=100>"; ?>
[/quote]

also, keep in mind that if you're going for validation, ALL your attribute values need to have quotes around them. so, putting quotes around the height and width as well is best practice:
<?php
echo "<img src='{$products[$i][phonepic]}' width='100' height='100'>";
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users