Create Image from another website.
 
SamBlaze

Sometime it is necessary to show image from another website. To illustrate, if you want to show your facebook profile picture to your resume, somehow you need to sync FB picture. Here is a easy way to show remote pictures.

Step 1:

Retrieve the whole html content from the remote server.

$html = file_get_contents(“http://url.of/the/website”);

Step 2:

Create a DOMDocument object.

$doc = new DOMDocument();

Step 3:

Get html element by id and get the src (source) of the image.

$imageTags = $doc->getElementsByTagName(‘img’);

foreach($imageTags as $tag) {

$imgUrl.=$tag->getAttribute(‘src’);

}

Step 4:

Create image from the source.

$im = imagecreatefrompng($imgUrl);

header(‘Content-Type: image/png’);

imagealphablending($im, false);
imagesavealpha($im, true);
imagepng($im);
imagedestroy($im);

Finally you need to create a php file to write all these codes. Now you can use the php file url as src to any image tag to show the remote image.

Leave a Reply

Your email address will not be published. Required fields are marked *


eight − 4 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Create Image from another website.

Sometime it is necessary to show image from another website. To illustrate, if you want to show your facebook profile picture to your resume, somehow you need to sync FB picture. Here is a easy way to show remote pictures.

Step 1:

Retrieve the whole html content from the remote server.

$html = file_get_contents(“http://url.of/the/website”);

Step 2:

Create a DOMDocument object.

$doc = new DOMDocument();

Step 3:

Get html element by id and get the src (source) of the image.

$imageTags = $doc->getElementsByTagName(‘img’);

foreach($imageTags as $tag) {

$imgUrl.=$tag->getAttribute(‘src’);

}

Step 4:

Create image from the source.

$im = imagecreatefrompng($imgUrl);

header(‘Content-Type: image/png’);

imagealphablending($im, false);
imagesavealpha($im, true);
imagepng($im);
imagedestroy($im);

Finally you need to create a php file to write all these codes. Now you can use the php file url as src to any image tag to show the remote image.

Leave a Reply

Your email address will not be published. Required fields are marked *


four − 2 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">