Reputation: 92
Can I pull an img tag from another website (using echo) and then style it through CSS to fit it into my own container div? My code is below - I'm just aiming to get the code to work and I will clean the code up later.
The major issue is I don't want to save the img into my files (it is dynamically changing from another source which I have parsed.) I was hoping I would be able to style a container div using max-height and width and just echo within that div but I haven't haven't had any luck changing the img size but I am able to adjust the margin within the container div and have the img respond so that is why I am here.
Would echoing the $compic->src work? If so what would that look like?
<!DOCTYPE html>
<html>
<header>
<title>Resize echo img</title>
<link rel="stylesheet" type="text/css" href="style.css">
</header>
<body>
<div class="headimg">
<?php
include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('url');
$compic = $html->find('img[title]', 0);
echo $compic
?>
</div>
</body>
Upvotes: 1
Views: 2452
Reputation: 570
if you wrap the img inside a parent element with a fixed with and height and the img element with width of 100% and a height of auto it should auto size
<div class="image-wrapper">
<img src="<?=$compic->src?>"> // not sure what the structure will be.
</div>
here is the css
.image-wrapper {
height: 100px;
width: 100px;
}
.image-wrapper img {
width: 100%;
height: auto;
}
using a structure like this lets you crop if the image is too tall, since sometimes aspect ratios don't match, you would do this by applying overflow hidden to .image-wrapper
Upvotes: 1