I have a code download image from link http://www.bitrepository.com/download-image.html
When start is link format: <img src='test[1].jpg'>
But when download this link is link become <img src='test3%5B1%5D.jpg'>
How to fix it?
code here
<?php
include_once 'class.get.image.php';
// initialize the class
$image = new GetImage;
$image->source = 'http://test.com/test[1].jpg';
$image->save_to = 'images/'; // with trailing slash at the end
$get = $image->download('gd'); // using GD
if($get)
{
echo 'The image has been saved.';
}
?>
Try this.
On this line
$image->source = 'http://test.com/test[1].jpg';
Changed to
$image->source = htmlspecialchars_decode('http://test.com/test[1].jpg');
Look up urldecode in php to change the encoded values back to brackets
Related
I have the following url - this url is not always the same though, but will always end the same:
$thumbnail_url = 'http://i2.ytimg.com/vi/552yWya5RgY/hqdefault.jpg'
using php I'd like to replace hqdefault.jpg with maxresdefault.jpg
so the new thumbnail would look something like this:
$hq_thumbnail_url = 'http://i2.ytimg.com/vi/552yWya5RgY/maxresdefault.jpg'
Is this possible?
str_replace() is probably your most simple approach...
$thumbnail_url = 'http://i2.ytimg.com/vi/552yWya5RgY/hqdefault.jpg';
$hq_thumbnail_url = str_replace('hqdefault.jpg', 'maxresdefault.jpg', $thumbnail_url);
Hope this helps!
Here's another way to do it, and it will work even if hqdefault.jpg isn't at the end of the url :
$url = 'http://i2.ytimg.com/vi/552yWya5RgY/hqdefault.jpg'; // Url you want to change
$newImage = 'newimage.jpg'; // New filename
$splitUrl = explode('/', $url); // Split the url at each '/' occurence
$splitUrl[5] = $newImage; // Change the old filename (hqdefault.jpg) with the new one
$newUrl = implode('/',$splitUrl); // Reform the url, but this time, with the new filename.
echo $newUrl; // Here's the modified url
I'm using Froalo for text editing, but I'm having difficulties getting the image upload to function correctly. Testing on localhost.
The documentation says that
imageUploadURL: '/upload_image.php',
should return a json string formated like this :
{ link: 'path/to/image.jpg' }
my javascript looks this this :
$(function() {
$('#edit').froalaEditor({
language:'fr',
imageUploadURL: 'upload.php'
})
});
my upload.php looks like this :
var_dump($_FILES);
require('clean.php'); // removes french special characters
$image = clean($_FILES['file']['name']);
$uploaddir = '../photos/';
$uploadfile = $uploaddir . basename($image);
$retour = ['link'=> $uploadfile];
$b = json_encode($retour);
$array_final = preg_replace('/"([a-zA-Z]+[a-zA-Z0-9_]*)":/','$1:',$b);
if( move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile)) {
echo stripslashes($array_final);
} else {
echo "Lo kol kakh tov...";
}
When I run this from the text editor through froalaEditor,
the file gets uploaded to the server,
firebug says that upload.php
answers the array $_FILES and :
{link:"../photos/sama1.jpg"}
That all seems good, but froala answers that "something" went wrong and the images doesn't appear in the editor.
Could it be because of the double quotes around the image url?
Solution was dead simple : the problem was this:
{link:"../photos/sama1.jpg"}
It didn't like the relative path so changing it to either this :
{link:"/var/www/html/blabla/photos/sama1.jpg"}
or this
{link:"/photos/sama1.jpg"}
did the trick :)
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 ?>">
i am trying to get a Minecraft player's skin via PHP, and it all works, until the user enteres an invalid username, techniclly, if that happenes the script should replace the not found image with an alternative image, but for some reason it doesn't.
full script:
<?php
//initial settings
header("Content-type: image/png");
//declere values
$name = $_GET['n'];
//get the image from Minecraft main servers
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/{$name}.png");
//if not found, use an alternative image
if(!$src){
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/char.png");
}
//display the skin
imagepng($src);
?>
Any help will be appriciated, thank you.
try
<?php
//initial settings
header("Content-type: image/png");
//declere values
$name = $_GET['n'];
//get the image from Minecraft main servers
if(file_exists("http://s3.amazonaws.com/MinecraftSkins/{$name}.png")) {
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/{$name}.png");
//if not found, use an alternative image
else {
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/char.png");
}
//display the skin
imagepng($src);
?>
Hello there i have a php file with the included:
The image shows properly when i access the PHP file, however when I try to show it in the HTML template, it shows as the little img with a crack in it, so basically saying "image not found"
<img src="http://konvictgaming.com/status.php?channel=blindsniper47">
is what i'm using to display it in the HTML template, however it just doesn't seem to want to show, I've tried searching with next to no results for my specific issue, although I'm certain I've probably searched the wrong title
adding code from the OP below
$clientId = ''; // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png'; // Set online image here
$offline = 'offline.png'; // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);
if ($json_array['stream'] != NULL) {
$channelTitle = $json_array['stream']['channel']['display_name'];
$streamTitle = $json_array['stream']['channel']['status'];
$currentGame = $json_array['stream']['channel']['game'];
echo "<img src='$online' />";
} else {
echo "<img src='$offline' />";
}
The url is not an image, it is a webpage with the following content
<img src='offline.png' alt='Offline' />
Webpages cannot be displayed as images. You will need to edit the page to only transmit the actual image, with the correct http-headers.
You can probably find some help on this by googling for "php dynamic image".
Specify in the HTTP header that it's a PNG (or whatever) image!
(By default they are interpreted as text/html)
in your status.php file, where you output the markup of <img src=... change it to read as follows
$image = file_get_contents("offline.png");
header("Content-Type: image/png");
echo $image;
Which will send an actual image for the request instead of sending markup. markup is not valid src for an img tag.
UPDATE your code modified below.
$clientId = ''; // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png'; // Set online image here
$offline = 'offline.png'; // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);
header("Content-Type: image/png");
$image = null;
if ($json_array['stream'] != NULL) {
$channelTitle = $json_array['stream']['channel']['display_name'];
$streamTitle = $json_array['stream']['channel']['status'];
$currentGame = $json_array['stream']['channel']['game'];
$image = file_get_contents($online);
} else {
$image = file_get_contents($offline);
}
echo $image;
I suppose you change the picture dynmaclly on this page.
Easiest way with least changes will just be using an iframe:
<iframe src="http://konvictgaming.com/status.php?channel=blindsniper47"> </iframe>