RewriteRule a <img src=...> or other solution - php

I want my IP cam streaming on my website.
Since I have this piece of code but if you look at the source code, you'll see of course the complete data as user and pass. That is not the intention, I looked at RewriteRule option in .htaccess but don't know how to formulate, or maybe another solution to protect my user and pass data. Who can help me get out the thinking circle and gives a move in the right direction (or example).
<?php
$url = '123.456.7.890:1234';
$user = 'naam';
$pass = 'wachtwoord';
$cam = "http://$url/videostream.cgi?user=$user&pwd=$pass";
?>
<html>
<body>
...
<img name="main" id="main" border="0" width="640" height="480" src="<?php echo("$cam"); ?>">
...
</body>
</html>

If camera response you with image you can get it in PHP code and then add it to image src like base64 data.
For example
<?php
$url = '123.456.7.890:1234';
$user = 'naam';
$pass = 'wachtwoord';
$cam = "http://$url/videostream.cgi?user=$user&pwd=$pass";
$image = file_get_contents($cam); // Or use CURL
// Here you need to replace $type of your camera
$image_src = 'data:image/' . $type . ';base64,' . base64_encode($image);
?>
<html>
<body>
...
<img name="main" id="main" border="0"
width="640" height="480" src="<?php echo $image_src ?>">
...
</body>
</html>

You should use your server side to create a image.
Solution can be found here: Create Image From Url Any File Type
You can create a PHP file that outputs the image or something.
If you do that, you can load the image like this: <img src="http://domain.com/image.php?id=1">
Then in image.php, you can load from your DB, or whatever you like.
However, when you have the real image info, you can make a "fake" image as descriped in the link above.

Related

Php display image from url into homepage

after no one answered at this question Php Rss feed use img in CDATA -> content:encoded i try to do something else solving this problem...
how can i load an image from a given url directly into my homepage?
<?php
$url = "...";
$image = file_get_contents("$url");
echo $image;
?>
*i don't want to save the image anywhere... just load the image from the url and show it in my own homepage.
Try this code,work fine on my machine.
<?php
$image = 'http://www.google.com/doodle4google/images/d4g_logo_global.jpg';
$imageData = base64_encode(file_get_contents($image));
echo '<img src="data:image/jpeg;base64,'.$imageData.'">';
?>
You are almost there. When you download the contents of the file you need to encode it to base64 if you do not plan to store it on server.
<?php
$url = '...';
$image = base64_encode(file_get_contents($url));
?>
Then you can display it:
<img src="data:image/x-icon;base64,<?= $image ?>">

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; ?>"/>

PHP Google Static Maps V2 error

I want to display a static map image with 3 markers, and somehow it is not working. It works with one marker, but doesn't display an image when I add more markers. The output url displays an image if I direct the browser to it, but doesn't seem to work in the php page.
<?php
$lat1=61.212311;
$lng1=61.211123;
$lat2=61.421113;
$lng2=61.411123;
$lat3=61.931121;
$lng3=61.912113;
$url="http://maps.googleapis.com/maps/api/staticmap?size=400x400&markers=color:blue%7Clabel:S%7C".$lat1.",".$lng1."&markers=size:tiny%7Ccolor:green%7C".$lat2.",".$lng2."&markers=size:mid%7Ccolor:red%7Clabel:C%7C".$lat3.",".$lng3."&sensor=false&key=";
$src = htmlspecialchars($url);
echo $src;
?>
<html>
<body>
<img src="<? echo $src; ?>" />
</body>
</html>
I am putting my API key, that is not the error.
you are defining variable $url1 and using $url, so change:
$src = htmlspecialchars($url);
to
$src = htmlspecialchars($url1);
and remove echo $src; from top

Secure images failing - Codeigniter

My script pretty much works, however when I run a for loop it fails, in the view:
<?php foreach($pics as $index=>$pic){?>
<td class='Pictures'>
<center>
<?php
$piece = explode('/',$pic["ThumbImg"]);
$string = $piece[5];
?>
<img src='<?php echo base_url(); ?>index.php/Controller/getImage/<?php echo $string; ?>/1' width="100px">
</a>
Controller class - Get image function:
//function to protect images from being accessed directly by obfuscating the URL
function getImage($img_id,$type){
if($this->members->logged_in()){
//code to authenticate user goes here then...
//code to decide which type of file it is/thumb/full size image
if($type==1)
{
$url = $this->data['base_url'].'system/application/images/pic/thumbs/';
}else if($type==0){
$url = $this->data['base_url'].'system/application/images/pic/';
}
$filepath = $url.$img_id;
//send image to web browser.
header("Content-type: image/jpeg");
//get path
$img_handle = imagecreatefromjpeg($filepath) or die("");
//create and send
ImageJpeg($img_handle);
}
I suspect that this could be due to the headers being resent, if so how can I resolve this.
Cheers
Fixed the problem - used "Hotlinking"
You will basically only need to set the header information header("Content-type: image/jpeg") if you're loading the image from the database. But since you're loading it from a folder you might want to skip the php file and immediately fetch the image from the folder:
<img src='<?php echo base_url(); ?>img_folder/<?php echo $string; ?>/1'
width="100px">

Get Twitter profile picture actual link

I'm trying to get the twitter profile picture actual link.
I know I can get the profile picture through the following link:
$test = "http://api.twitter.com/1/users/profile_image?screen_name=".$nickname."&size=original"
but when I want to get the file contents of this url, it doesn't work, cause above mentioned link is redirected to the actual link of the profile picture. So this doesn't work:
file_get_contents($test);
How can I get the actual link of the profile picture and then with the size original?
Try this it might help you.
<?php
function getTwitterProfileImage($username) {
$size = '_bigger';
$api_call = 'http://twitter.com/users/show/'.$username.'.json';
$results = json_decode(file_get_contents($api_call));
return str_replace('_normal', $size, $results->profile_image_url);
}
$img = getTwitterProfileImage('thetutlage');
echo '<img src="'.$img.'"/>';
?>
Try this is up+direct,
<img class="img-rounded" src="<?php
$size = '';
echo str_replace('_normal', $size,$tweet->user->profile_image_url)
?>"
height="250px" width="400px" />

Categories