How to decode a base64 string (gif) into image in PHP / HTML - php

I have a base64 encoded string that I would like to convert into an image in PHP / HTML.
Here is what I have:
$data = "R0lGODdhAAGAAKIAAP38+/3h3cjN5P3HwgAAAP8AoP8AGv8EIywAAAAAAAGAAAAD.....";
echo base64_decode($data);
// OR
echo '<img src="data:image/gif;base64,' . base64_decode($data) . '" />';
None of those work. Any suggestions?
Much appreciated!
Catalin

In the first case you should add this before echoing the decoded image data:
header("Content-type: image/gif");
In the second case, use this instead:
echo '<img src="data:image/gif;base64,' . $data . '" />';

Display Image using base64_encode function
$ret = fopen($fullurl, 'r', true, $context);
$contents = stream_get_contents($ret);
$base64 = 'data:image/PNG;base64,' . base64_encode($contents);
echo "<img src=$base64 />" ;

echo '<img src="data:image/gif;base64,' . $data . '" />'
Should do the trick.

Stupid question: is the mime-type correct?? is your base64 code represent a gif file????
this is an example using a image/png, without php, just html, and it works:
<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABBCAIAAAABlV4SAAAABGdBTUEAAK/INwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAABJFSURBVHja1FoLmFTFla5zqu7tGRgRGB4J
gkAAgSUBgyiQiIpm1UCMH6hIYkiUuJ8xhjjyIWuCGt9mjZtPTUwiefkI0fURCGh0VTRCAJOwiCyP
CCJiEBSGcWZ6Hj3d91btOafu7ekhX1B7ZL5v23a4fW91ddV5/uc/pdRH9kL6H/iNxeviffoAJXf8
BYAf7D90mAqSL6bzwOF+WH90e3C8UJALfqO/k/5Nlwp+L8UBTu7SMpw8whEj8NwZymi9dy89tX5o
MvhIv0D5DSCkgveCRC8m/xFQF5VwqBLD228B59C5zEVfwiCEVKWpJrvgBbK4jhtIFoqsH+0/HD9O
V3ZPH4AyYmRzLzGFpsA5ZZ0ZPMiUrBsBunAPqsSyAaDUMfwOZ19oNr4c3PufpsKA3wNtLMzA+jUk
e0MasA6OG2YSv2n3HkzE03XbSM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FDL7TfJabyYD1z4soaD
UhO7wXfnM9YgH/A4JeE5myguiwW28Bi+z0/1OdMypcfQuurcXtosHT0SCE57yM1ld7Py6PWUSUk8
6NMPqJz41WId12uXkyMbWd/85CbZmj8iFdPtTtx1R0A7Wimtde6lZOg6OfaWYwfY8Fdz+lR+FIbh
F79YcdcPKvNNGOVYY9aX0zHO+UrxGJc3I9115z89bWpKW+hyeuw7C7Xvn9k0+JCd/HkVbn2FcZ4/
eOgfff9Wk3JCmPiAcEvQdbqA4gngogxN0cJuuD7T1shHVqVU8oeawAef7Zux5sqg/YulEVxiIJTr
0R/6WwSGLcQ+kxebTJAWSILNcOIkO2USDh0MQ45R3arUi6vh5w/F7+5BYSnTI+sppkwnkY/QFUfT
i+ouNsx1IsK0b1QC9n0NgKVG4k8RwKFt/COYB/5/vP5PgAEA77fJf3rfdyAAAAAASUVORK5CYII=" />
Just try it.
Now, the same base64 code using the php exemplified above but using the proper mime-type (image/png):
<?php
echo "<img alt=Embedded Image src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABBCAIAAAABlV4SAAAABGdBTUEAAK/INwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAABJFSURBVHja1FoLmFTFla5zqu7tGRgRGB4J
gkAAgSUBgyiQiIpm1UCMH6hIYkiUuJ8xhjjyIWuCGt9mjZtPTUwiefkI0fURCGh0VTRCAJOwiCyP
CCJiEBSGcWZ6Hj3d91btOafu7ekhX1B7ZL5v23a4fW91ddV5/uc/pdRH9kL6H/iNxeviffoAJXf8
BYAf7D90mAqSL6bzwOF+WH90e3C8UJALfqO/k/5Nlwp+L8UBTu7SMpw8whEj8NwZymi9dy89tX5o
MvhIv0D5DSCkgveCRC8m/xFQF5VwqBLD228B59C5zEVfwiCEVKWpJrvgBbK4jhtIFoqsH+0/HD9O
V3ZPH4AyYmRzLzGFpsA5ZZ0ZPMiUrBsBunAPqsSyAaDUMfwOZ19oNr4c3Pufp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gwITuauMGTnGwQxJV9B9/cyrKPZQP/vhCNbwB20UmH9FDL7TfJabyYD1z4soaD
UhO7wXfnM9YgH/A4JeE5myguiwW28Bi+z0/1OdMypcfQuurcXtosHT0SCE57yM1ld7Py6PWUSUk8
6NMPqJz41WId12uXkyMbWd/85CbZmj8iFdPtTtx1R0A7Wimtde6lZOg6OfaWYwfY8Fdz+lR+FIbh
F79YcdcPKvNNGOVYY9aX0zHO+UrxGJc3I9115z89bWpKW+hyeuw7C7Xvn9k0+JCd/HkVbn2FcZ4/
eOgfff9Wk3JCmPiAcEvQdbqA4gngogxN0cJuuD7T1shHVqVU8oeawAef7Zux5sqg/YulEVxiIJTr
0R/6WwSGLcQ+kxebTJAWSILNcOIkO2USDh0MQ45R3arUi6vh5w/F7+5BYSnTI+sppkwnkY/QFUfT
i+ouNsx1IsK0b1QC9n0NgKVG4k8RwKFt/COYB/5/vP5PgAEA77fJf3rfdyAAAAAASUVORK5CYII=\" />";
?>
So, this is the code:
echo "<img alt=Embedded Image src=\"data:image/png;base64,[BASE64CODE]\" />";
Notice, since I am using double quotes for the echo tag, I have to tell php to ignore the ones inside the img tag. Other than that, you are good
cheers
PC

You have to use the header() function before echoing your data to specify the content type (gif image). Otherwise browsers will interpret it as html.

Related

How to Display Remote Image?

I need to have a working remote IMG display using PHP, let's say like this:
<img src='$src' />
And I need to fetch the remote URL based on $id, where
<?php
$id = "brown_fox";
$url = "http://exampl.com/$id";
get_remote_img($url) {
// some code to get image which SRC is dynamic:
<img id="pic" src="sjf5d85v258d.jpg" />
$src="sjf5d85v258d.jpg";
return $src
}
?>
I hope I explained it understandably.
If I understand you correctly then you can do something like this:
<?php
...
get_remote_img($url) { ...
$src = get_remote_img($url);
// Concatenating the result to the elements src attribute:
echo '<img src='.$src.' />';
?>
What you're looking for is something like this:
<?php
$id = "brown_fox";
$url = "http://exampl.com/" . $id;
...
function get_remote_img($url) {
// some code to get image which SRC is dynamic:
$src="sjf5d85v258d.jpg";
echo "<img id=\"pic\" src=" . "\"" . $src . "\"" . "/>";
return $src;
}
?>
Also, if you want to send and receive query parameters in the URI dynamically through a form, you can take a look at GET Request in PHP.

php convert string(stream) to image

I using php 5.6.
And Get Json Data to Delphi Datasnap Middleware.
Here is Data Sample
71,73,70,56,57,97,211,1,60,0,85,0,0,33,249,4,1,0,0,47,0,44,0,0,0,0,211,1,60,0,133,255,255,255,0,0,0,153,102,0,102,204,255,102,153,255,255,255,204,102,51,51,255,204,102,153,255,255,255,255,153,255,153,102,204,255,255,51,102,204,0,102,153,204,102,51,102,0,102,102,51,0,0,0,102,51,51,102,102,0,0,0,0,51,0,51,102,51,0,0,51,0,102,102,102,102,102,0,51,153,102,51,51,0,51,102,51,102,102,102,153,153,255,153,51,102,153,204,102,102,153,204,102,102,102,204,204,153,153,0,102,102,153,102,102,0,51,51,51,51,51,51,102,102,102,204,204,204,204,255,153,153,102,204,255,153,102,102,0,153,153,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,255,64,128,112,72,44,26,143,200,164,114,201,108,58,159,208,168,116,74,173,90,175,216,172,118,203,237,122,191,224,176,120,76,46,155,207,232,180,122,205,110,187,223,240,184,124,78,175,219,239,248,188,126,207,239,251,255,128,129,130,131,132,67,5,16,4,87,5,6,3,81,2,137,83,143,80,139,141,145,144,78,148,150,106,7,18,11,84,153,80,146,133,73,160,154,79,165,163,88,7,22,1,1,12,134,140,138,177,161,151,71,135,173,1,21,158,66,162,75,148,168,70,14,184,17,8,68,189,77,192,78,199,69,2,184,184,186,85,14,175,156,187,71,9,19,206,184,13,0,201,67,210,70,203,169,176,149,73,194,173,196,198,181,76,221,226,90,236,68,171,217,1,232,192,183,206,232,188,234,68,215,175,66,14,248,225,226,81,168,244,107,214,17,1,208,0,40,24,56,100,89,60,121,219,222,93,211,150,238,200,42,125,11,201,45,57,176,129,220,55,106,77,14,92,40,54,46,73,184,112,198,92,229,121,184,173,164,201,132,25,27,234,83,242,14,73,179,126,71,20,224,228,243,80,30,129,255,154,200,12,10,41,149,224,129,7,108,173,102,10,81,208,82,102,190,34,28,27,41,160,199,136,157,72,146,75,155,162,204,90,196,106,199,134,9,81,126,59,50,150,9,72,127,211,58,53,17,86,139,221,33,125,91,189,41,133,19,19,128,128,166,239,174,18,97,234,116,31,82,103,12,129,146,157,171,179,29,55,161,74,198,58,216,214,44,0,67,34,68,31,96,141,203,183,162,93,117,2,112,102,62,60,192,234,7,168,106,47,39,169,236,18,92,91,68,79,141,172,218,233,239,49,19,5,9,1,124,12,173,228,26,6,124,156,145,172,106,57,49,41,77,14,88,233,188,53,132,58,183,238,207,240,66,47,43,26,28,50,226,117,192,71,179,230,201,234,28,73,193,92,1,104,32,87,207,32,243,190,182,32,224,252,71,242,88,130,12,228,96,47,40,168,17,222,200,189,90,231,58,136,109,220,52,228,226,141,93,55,132,24,42,246,236,106,72,92,211,192,33,9,177,35,0,10,146,49,51,23,0,103,213,209,160,108,45,229,245,222,16,164,45,151,160,45,207,109,68,155,17,133,253,161,255,151,16,81,113,3,65,43,250,89,212,73,2,28,120,146,95,123,145,77,182,160,93,207,84,99,222,133,12,118,194,222,75,187,212,37,90,120,184,213,7,213,87,188,132,245,98,21,215,12,212,91,90,0,170,102,65,132,16,4,150,225,84,8,204,7,96,92,10,77,183,68,145,3,92,67,204,53,244,173,51,226,43,10,204,67,18,105,217,213,132,80,142,174,89,216,92,105,78,116,136,132,155,126,25,57,193,150,19,116,137,198,135,12,126,133,29,0,204,61,244,74,61,35,222,115,20,46,67,218,84,203,119,32,86,55,80,77,230,136,105,25,135,17,180,208,86,134,66,244,22,64,83,59,122,1,91,11,227,33,137,196,45,234,100,148,76,93,103,130,119,196,118,82,20,192,129,7,15,132,176,65,10,28,132,48,33,20,219,45,6,10,153,10,69,72,169,55,195,4,167,230,167,129,150,152,4,170,210,125,186,106,171,175,198,58,235,26,61,225,35,88,152,1,152,96,1,125,123,154,74,156,60,184,12,100,30,122,20,234,114,35,23,215,16,0,37,155,86,52,134,109,54,86,14,17,255,238,184,178,121,58,5,48,2,232,231,192,99,113,33,10,5,39,24,32,48,21,6,3,168,23,69,81,43,76,51,225,131,139,13,181,235,20,246,118,117,176,17,9,115,152,46,190,250,70,192,175,191,118,84,251,233,194,246,93,73,99,106,13,105,22,81,85,24,227,105,151,149,135,180,84,170,143,251,108,220,104,161,145,152,12,205,127,91,20,160,194,18,148,97,250,132,3,39,36,34,128,9,34,180,43,133,2,36,116,224,15,94,197,137,8,9,118,34,111,86,68,195,228,46,129,171,195,72,224,172,51,207,62,223,81,173,61,206,164,203,32,114,25,215,182,113,166,32,126,21,211,183,74,176,203,241,16,187,17,71,85,123,234,94,104,174,51,54,27,77,197,201,4,46,0,179,18,111,103,35,44,202,103,23,225,0,203,204,68,4,129,183,69,63,33,0,64,181,144,138,23,198,10,245,24,142,165,232,90,252,183,211,233,222,37,34,225,128,131,193,116,20,23,129,211,35,218,92,43,200,68,195,225,64,251,24,217,1,102,128,65,83,252,44,61,129,62,5,179,179,57,77,133,63,145,255,128,11,81,187,155,106,134,221,108,69,201,8,73,94,201,109,231,34,35,83,92,195,44,57,199,54,195,170,179,62,129,214,23,47,31,61,240,197,50,223,8,241,203,174,49,251,205,36,103,120,64,232,82,144,94,40,234,70,28,242,202,225,197,28,248,181,47,148,218,107,233,222,195,113,113,247,238,203,91,92,35,11,29,4,175,4,72,254,50,5,130,244,186,9,13,83,20,48,190,133,153,207,46,232,80,223,154,104,194,56,16,73,0,127,250,91,138,149,248,7,13,255,1,176,12,219,115,66,231,152,97,39,6,85,7,91,113,99,216,215,168,52,142,188,88,0,39,50,179,156,142,214,209,190,4,45,166,23,15,26,74,160,64,72,133,249,69,161,27,246,11,83,143,86,241,57,34,140,197,114,178,81,9,218,44,208,67,111,140,231,82,152,56,216,106,12,161,2,21,238,45,122,234,154,211,2,21,226,168,148,156,75,136,63,108,137,48,160,135,193,191,200,163,136,54,241,73,26,72,168,48,0,82,143,56,77,129,19,251,164,119,36,62,253,229,137,98,136,225,41,120,55,67,121,116,255,112,127,153,195,227,23,106,114,70,25,166,145,139,202,51,140,32,7,73,200,61,16,11,11,135,44,164,34,23,201,200,70,106,238,117,89,8,151,35,39,73,201,74,90,242,146,152,204,164,38,55,201,201,78,122,242,147,160,12,165,40,71,73,202,82,154,242,148,168,76,165,42,87,201,202,86,186,242,149,176,140,165,44,103,73,203,90,218,242,150,184,204,165,46,119,153,10,251,145,49,60,121,252,101,28,132,105,45,59,16,19,108,77,56,38,50,121,105,24,95,190,200,79,77,235,88,215,246,160,204,128,124,48,27,33,188,15,182,140,180,62,154,233,195,82,152,170,102,48,243,200,204,72,8,17,106,83,72,30,185,176,102,157,98,6,5,128,39,33,167,47,48,80,141,2,208,211,9,141,10,64,45,150,227,197,42,46,51,9,223,179,2,211,242,134,196,190,121,51,39,36,106,207,50,216,217,10,205,200,179,156,81,152,92,78,0,153,19,122,45,142,69,222,49,202,95,148,210,147,108,252,164,125,19,136,155,50,205,210,51,180,149,148,9,39,107,157,65,151,70,35,107,158,43,155,255,126,75,136,148,248,180,190,68,138,206,112,24,65,71,136,220,233,55,135,66,84,12,170,154,162,26,141,119,137,248,117,135,28,246,26,41,223,252,65,2,110,61,74,11,255,35,66,84,71,183,49,68,145,176,65,1,217,80,20,40,166,52,166,217,244,169,249,244,40,50,207,147,158,112,14,169,44,74,253,169,6,181,74,33,138,130,6,64,5,67,89,139,120,90,169,55,18,36,88,26,137,138,217,254,89,5,123,214,243,158,84,13,206,135,72,88,150,101,118,20,48,23,4,209,132,68,225,85,120,102,206,33,180,41,202,160,124,179,4,180,62,84,173,175,209,218,80,69,164,18,29,142,201,102,149,57,106,219,92,148,4,73,86,138,91,201,216,224,188,200,209,24,48,98,73,75,8,224,82,146,8,184,151,162,126,137,138,184,73,233,243,232,234,163,180,238,239,61,241,235,77,108,190,186,31,127,194,168,21,102,45,2,153,74,225,144,107,54,148,183,152,173,2,113,37,56,172,1,216,106,22,184,10,45,98,24,26,129,201,234,179,180,78,229,19,106,17,19,166,196,9,145,140,170,98,255,149,171,96,37,171,230,148,32,56,239,45,66,173,6,36,148,124,238,115,65,184,90,209,113,175,136,11,232,145,85,188,149,104,44,60,136,152,62,117,28,48,72,187,208,111,174,2,217,55,57,66,55,186,225,235,38,117,173,241,128,128,49,104,96,27,138,171,51,105,151,45,130,8,197,175,120,27,18,196,246,213,47,250,36,64,104,234,66,113,219,44,92,60,147,204,165,120,190,61,200,21,187,187,190,188,197,102,25,20,51,14,100,171,33,217,141,190,213,36,237,132,48,22,158,182,151,116,1,13,197,113,149,155,12,143,214,192,7,99,40,177,211,140,90,206,236,66,181,194,42,36,113,161,10,218,208,112,26,32,72,222,116,192,47,21,168,132,93,172,220,216,128,98,57,225,37,211,142,201,44,100,45,72,244,77,149,67,220,94,44,26,205,128,30,100,72,4,133,41,103,177,169,12,193,97,174,8,241,29,66,160,27,34,103,101,204,164,188,119,126,130,157,53,20,188,205,109,110,161,16,208,138,144,32,85,140,157,54,216,185,9,229,107,155,111,200,136,62,42,151,100,199,251,154,58,255,13,182,188,69,127,217,34,39,4,199,222,16,237,55,48,170,107,120,22,72,132,200,78,188,15,21,47,185,82,95,219,211,68,148,226,82,26,154,133,173,142,238,38,74,204,149,92,14,101,250,169,201,188,236,166,209,246,192,252,193,217,68,57,106,0,109,89,88,106,240,113,47,60,86,178,50,116,41,232,9,11,14,97,170,66,0,183,3,163,61,109,82,55,65,64,33,86,13,91,21,189,238,210,142,153,22,142,24,231,178,175,224,89,43,158,171,31,101,17,134,158,25,12,21,76,83,4,160,169,102,198,170,191,219,234,41,26,145,23,90,60,39,136,135,2,216,131,251,163,160,209,52,69,114,34,24,146,118,7,232,221,92,134,55,45,96,59,111,63,216,79,25,242,128,30,67,207,57,135,145,199,72,227,96,222,38,148,15,155,53,107,244,243,30,6,143,50,74,229,221,241,154,219,252,230,56,207,185,206,119,206,243,158,251,252,231,64,15,186,208,135,78,244,162,27,253,232,72,79,186,210,151,206,244,166,59,253,233,80,143,186,212,167,78,245,170,91,253,234,88,207,186,214,3,241,44,130,174,123,253,235,96,15,187,216,199,78,246,178,155,253,236,104,79,187,218,215,206,246,182,187,253,237,112,143,187,220,231,78,247,186,219,253,238,120,207,123,215,131,0,0,59
This data is convert stream(or String) to blob image(only gif).
Attachment Image
So, I create gif to this data,
How do I convert Image to this Data?
Here is My php code When get json data
$fullcurl = "http://addr";
$result = file_get_contents($fullcurl);
$im = imagecreate(200, 200);
$bg = imagecolorallocate($im, $result);
header("Content-type: image/gif");
imagepng($im);
this code not working.
And another try to
$fullcurl = "http://addr";
$result = file_get_contents($fullcurl);
<img src="data:image/gif;base64,<?=base64_encode($result['Ask'])?>" />
Not working.
I think your data sample is not correct.
I converted following gif to base64 and it is working as below code sample.
http://netdna.webdesignerdepot.com/uploads/2008/11/sample-graphic.gif
<?php
$image = 'R0lGODlhJgKQAdUAAElNS////wCZ/xt8u2/F/5mZmWtubDJlg8/s/8bHxyCm/xKG0pDT/0VRVkCz
/+/5/4GEg6/f/6+xsN3d3VRXVjxbbCVzpQmP6AWU9DCs/1ZfYXZ5d7q8u9HS0n/M/1C5/7/l/xeB
xyB4sEBWYRCf/9/y/zdgd+jp6PT09I2Pjp/Z/w6L3aSmpSlumS5pjnDG/19jYZTW/4DM/973/wAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAHAP8ALAAAAAAmApABAAb/wIBw
SCwaj8ikcslsOp/QqHRKrVqv2Kx2y+16v+CweEwum8/otHrNbrvf8Lh8Tq/b7/i8fs/v+/+AgYKD
hIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8
vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T1
9vf4+fr7/P3+/wADChxIsKDBgwgTKlzIsK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YgURyg/aXg2xg
g9KHgz5YgxGYexYyhHkQg8A3g0h4ByrCfC/ShHwggu9CglJ4BxpCeh9yhX/AI493hFwICFSoK1YY
hnsQIONiIGZICA8whpHyApSyhoHwHsBCH3KYCOaRKutxh4zwHYoyHnzoCH7IJoAYiJDAHGAiHYZY
CSUgA8u3IAogA7u3iJaAAC/wiOmhAC/Qg5QoCanRfuEBG5zYiZegGZyBHqNRGqTICoghAy8gGaEh
GS8gA5axirZ4i7iYi7q4i7zYi/+++IvAGIzCOIzEWIzGeIzImIzKuIzM2IzO+IzQGI3SOI3UWI3W
eI3YmI3auI3c2I3e+I3gGI7iOI7kWI7meI7omI7quI7s2I7u+I7wGI/yOI/0WI/2eI/4mI/6uI/8
2I/++I8AGZACOZAEWZAGeZAImZAKuZAM2ZAO+ZAQGZESOZEUWZEWeZEYmZEauZEc2ZEe+ZEgGZIi
OZIkWZImeZIomZIquZIs2ZIu+ZIwGZMyOZM0WZM2eZM4mZM6uZM82ZM++ZNAGZRCOZREWZRGeZRI
mZRKuZRM2ZRO+ZRQGZVSOZVUWZVWeZVYmZVauZVc2ZVe+ZVgGZZiOZZkWZZmeZYGaJmWbBAEADs=';
echo '<img alt="sample.gif" src="data:image/gif;base64,' . $image .'" />';
Or if you are reading from file.
<?php
$data = file_get_contents('sample.gif');
echo '<img alt="sample.gif" src="data:image/gif;base64,' . base64_encode($data) .'" />';

PHP mail() - Images don't always load

I have a PHP mail script which is basically the following:
$result = mail($to, $subject, $message, $headers);
if(!$result) {
echo "Error";
} else {
echo "Success";
}
The $message is a HTML email that mostly renders fine in my email client except the images seem to only load sporadically.
The images are all like so:
<img src='http://www.mywebsite.com/media/twitter.png' />
I don't understand why some would load and some wouldn't, when they are all set up the same way.
I've read that it's better to embed images into the email as attachments but I'm unsure how to do this. It seems that you add a line like so:
<img src='cid:123456789'>
But what does this reference? How would I encode an image like this?
Any help would be appreciated!! Thanks
You would have to base64 encode the file.
I found a code example on github. I have not tested it myself but should give you a good nudge in the right direction...
$picture = file_get_contents($file);
$size = getimagesize($file);
// base64 encode the binary data, then break it into chunks according to RFC 2045 semantics
$base64 = chunk_split(base64_encode($picture));
echo '<img src="data:' . $size['mime'] . ';base64,' . "\n" . $base64 . '" ' . $size[3] . ' />', "\n";
Source : https://gist.github.com/jasny/3938108
Just as a side note. Are the images that you are using web optimised? Large images might be blocked by email clients, or just not downloaded by email clients.

Image tag src attribute not working in wordpress

I am creating a Google chart in wordpress, chart is rendered and stored into an image. However I am not able to call the image using <img src="" />. Following is the code:
$filepath = "/wp-content/uploads/graph.png";
file_put_contents($filepath, $response);
echo $filepath;
echo "<img src=\"/wp-content/uploads/graph.png\">";
I have also tried with http://*/graph.png which is not working. If I open the same in different browser, image is showing properly.
Try this
echo '<img src="' . get_bloginfo('template_directory') . '/images/logo.gif" />';
Go for 'template_directory' or 'stylesheet_directory'.
You may try the below code;
Much better if you combine your HTML code and PHP code. Much cleaner easy to read.
PHP code
<?php
Try changing your file path to
$filepath = "../../wp-content/uploads/graph.png";
file_put_contents($filepath, $response);
?>
HTML Code
<img src="<?php echo $filepath; ?>"/>

JSON escaping slashes in a file path, wont display image

I'm using PHP and a for loop to prepare data into proper html and output the data using JSON to be appended and displayed on the page. JSON slash escaping is causing the html to be viewed incorrectly by the browser.
This is my PHP for loop:
$json = '<div id="rsec3" class="rsec">';
for($i=0; $i<count($array); $i++)
{
$coverart = $array[$i]['cover'];
if(empty($coverart))
{
$coverart = "nocoverart.gif";
}
$json .= '<div><img="/video/cover/thumbs/' . $cover . '"></div>';
}
$json .= '</div>';
$json = json_encode(array('ok' => 'ok', 'html' => $json));
echo $json;
This is my javascript parsing and appending the json:
$.get('/index_get.php?iid='+this.id,function(data){
$('#indload').hide();
js=jQuery.parseJSON(data);
$('#indr').append(js.html);
});
This is what the browser is displaying, a bunch of useless jargon, and it is appending a </img="> on its own?
<img=" video cover thumbs img.png"></img=">
How can I prevent this from occuring, and having the image displayed properly?
I think problem could be invalid HTML tag <img> on the php code. In the <img> tag, src is missing and <img> tag was not closed.
Change the following
$json .= '<div><img="/video/cover/thumbs/' . $cover . '"></div>';
to
$json .= '<div><img src="/video/cover/thumbs/' . $cover . '" /></div>';
you need to close the image tag in your string
$json .= '<div><img="/video/cover/thumbs/' . $cover . '"/></div>';

Categories