I have the following syntax:
echo "<img src=\"images2/" . $row['image'] . "\" alt=\"\" /><br />"; }
I would like to a give a specific height and width for the image, but I can't to do it.
You can specify dimensions directly in your HTML <img> tag:
echo "<img src=\"images2/\" . $row['image'] . "\" alt=\"\" height=\"100\" width=\"100\" /><br />";
Note that your posted code has a closing curly brace (}) following your echo statement, which will cause a PHP error if there's no corresponding opening curly brace. You're also incorrectly escaping the double-quotes after images2/, which will result in invalid markup.
A better approach would be to enclose your entire markup in single quotes so that you don't have to escape the double quotes enclosed within:
echo '<img src="images2/' . $row['image'] . '" alt="" height="100" width="100" /><br />';
EDIT:
For modern day markup (depending on your requirements), it's considered vastly preferable to modify image dimensions in CSS, rather than in your <img> tag. You may want to consider implementing something akin to the following:
<style type="text/css">
img {
width: 100px;
height: 100px;
}
img.large {
width: 200px;
height: 200px;
}
</style>
<?php
echo '<img src="images2/' . $row['image'] . '" alt="" /><br />'; // no class attribute, so will default to 100x100
echo '<img src="images2/' . $row['image'] . '" alt="" class="large" /><br />'; // class attribute is `large`, so will rescale to 200x200
This should work
echo '<img src="images2"'.$row['image'].'\ alt="" width="" height="" /><br />'; }
Related
I am using the php code below to echo an image from mysql database, please help me show how can I set the width and height of the image?
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
This has nothing to do with SQL, it's a matter of CSS.
The CSS rules you need are width and height, and you can specify them either in the tag itself
echo '<img style="width: x; height: y" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
or in a style tag in your header section
echo '<style type="text/css">
#venue{
width: x;
height: y;
}
</style>'
...
echo '<img id="venue" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
or even in a separate file
yourStyle.css
#venue{
width: x;
height: y;
}
yourPHPfile.php
echo '<link rel="stylesheet" type="text/css" href="yourStyle.css" />';
...
echo '<img id="venue" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
You can read more about how CSS works and the different places it can be placed here (and in many other places, you can just search "CSS where").
There are multiple ways to do this, on simple solution is to echo the image with proper styling, something like this
echo '<img style="width: 500px; height: 200px" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
Another solution is to add a class or an ID to your image and then create a CSS rule to style it
echo '<img id="foo" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
And in your CSS
#foo{
width: 500px;
height: 200px;
}
//top of the code just consists of an if statement and some code.
case 'itemimage' :
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href=' . <?php grab_item_image(); ?> . "</div>"';
break;
}
}
That was my attempt but it does not look rite on my text editor. I am also using inline-css not sure if that matters.
The only thing that i'm trying to echo out is this div with the function providing an href.
<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href="#thephpfunctionhere"</div>
It's kind of confusing me with all the single and double quotes.
Quotes Problem and you started <?php again. Use the code below
//top of the code just consists of an if statement and some code.
case 'itemimage' :
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . grab_item_image() . '" /></div>"';
break;
}
}
Hope this helps you
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . <?php grab_item_image(); ?> . '"></div>"';
The image needs the ''SRC'' attribute instead of href. Also, since you are echo-ing within a php-tag you don't have to open the <\?php again but directly refer to the function.
echo
'<div class="product-preview-image" style="background: red; height:75px; width:75px;">' ,
'<img src="' . grab_item_image() . '" />' ,
'</div>"';
Komma's are even faster when using a direct echo. Not suitable for assigning it to a $variable
my code is:
$retval = preg_match('/<img.+src=[\'"](?P<src>.+)[\'"].*>/i', $content, $image);
$imgreal = str_replace(""", "\"", $image['src']);
if ($retval=="0") $imgthumb = ""; else $imgthumb = "<img align='left' src='".$imgreal."' width=100 />";
I need to extract an img from a string, but this gave me all time:
"http://www.racingzone.hu/pictures/news/mid/simroc-3---nyolc-uj-auto_2012-09-21-1348222495.jpg" alt="" width="490" height="214
How can I change those "es to normal chars "?
I tried htmlspecialchars_decode but that not worked to.
edit: the string coming from az sql table.
original string from mysql:
<p><img style="float: left; margin: 3px;" src="http://www.racingzone.hu/pictures/news/mid/simroc-3---nyolc-uj-auto_2012-09-21-1348222495.jpg" alt="" width="490" height="214" /></p>
<p>todik púőúőóüsztotodik púőúőóüsztotodik
string created by TinyMCE
coding in the table: latin2_hungarian_ci
Why does everybody always want to do these kind of things with a regex?
Simply:
$data='<p><img style="float: left; margin: 3px;" src="http://www.racingzone.hu/pictures/news/mid/simroc-3---nyolc-uj-auto_2012-09-21-1348222495.jpg" alt="" width="490" height="214" /></p>
<p>todik púőúőóüsztotodik púőúőóüsztotodik';
$a=explode('src="',$data);
if(count($a)<2)
{
echo 'no image';
die;
}
$p=strpos($a[1],'"',0);
if($p===false){
echo 'no quote found';
die;
}
$url=substr($a[1],0,$p);
echo $url;
Output:
http://www.racingzone.hu/pictures/news/mid/simroc-3---nyolc-uj-auto_2012-09-21-1348222495.jpg
is there something wrong from with my code? something hidden quote i forgot to close.
{
echo '<div class="project_box" title="'. $row['title']. '">';
echo '<p class="project_title">' . $row['title'] . '</p>';
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200"</img>';
echo '</div>';
}
when i echo this in my project box it has some space between the bottom of the image, and the bottom border i give to the div. i give the box a height "auto".
this is the div i place the echo'ed stuff in;
.project_box{
float:left;
width: 200px;
height: auto;
border: 1px solid #dbae78;
opacity: 0.7;
}
i cant find the problem:( i hope you see the problem in my code what i didn't see atm.
i want the border sticks to the bottom of the image.
It looks like
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200"</img>';
Should be
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200" />';
The img tag is a self closing tag, meaning it won't have a <img> and a </img>, only a <img/>. Also, even if it did, you still didn't have the closing bracket on the beginning of the tag.
Hello im using page nation which is amazing but now im trying to print off there avaratar im using this code
echo "<IMG SRC=\"$list['avatar']\" WIDTH=\"268\" HEIGHT=\"176\"
BORDER=\"0\" ALT=\"\" \/>";;
but im getting this error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in test.php on line 64
Try
echo "<IMG SRC=\"".$list['avatar']."\" WIDTH=\"268\" HEIGHT=\"176\"
BORDER=\"0\" ALT=\"\" />";
instead, or you could use this one, too
echo "<IMG SRC=\"{$list['avatar']}\" WIDTH=\"268\" HEIGHT=\"176\"
BORDER=\"0\" ALT=\"\" />";
or better and readable ones:
echo '<IMG SRC="'.$list['avatar'].'" WIDTH="268" HEIGHT="176" BORDER="0" ALT="" />';
echo '<IMG SRC="', $list['avatar'], '" WIDTH="268" HEIGHT="176" BORDER="0" ALT="" />';
I prefer this
echo "<IMG SRC=\"$list[avatar]\" WIDTH=\"268\" HEIGHT=\"176\" BORDER=\"0\" ALT=\"\" />";
eliminate de braces surrounding the variable and the single quotes for the array key
this should work :
echo '<IMG SRC="'.$list['avatar'].'" WIDTH="268" HEIGHT="176"
BORDER="0" ALT="" />';
to avoid all thet mess
?><IMG SRC="<?=$list['avatar']?> " WIDTH="268" HEIGHT="176" BORDER="0" ALT="" /><?php
and don't post your usual "parse error" comment here.
but check your other PHP syntax issue somewhere else
Try changing it to:
echo "<IMG SRC=\"{$list['avatar']}\" WIDTH=\"268\" HEIGHT=\"176\" BORDER=\"0\" ALT=\"\" />";
...or, less confusingly:
echo '<IMG SRC="'.$list['avatar'].'" WIDTH="268" HEIGHT="176" BORDER="0" ALT="" />';
Try it like this:
echo '<IMG SRC="'.$list['avatar'].'" WIDTH="268" HEIGHT="176" BORDER="0" ALT="" />';