Skip to content

Instantly share code, notes, and snippets.

@brantje
Created July 20, 2014 15:25
Show Gist options
  • Save brantje/439bfb51ca75e820249f to your computer and use it in GitHub Desktop.
Save brantje/439bfb51ca75e820249f to your computer and use it in GitHub Desktop.
<?php
/**
* ownCloud - passman
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <brantje@gmail.com>
* @copyright Sander Brand 2014
*/
function getURL($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$tmp = curl_exec($ch);
curl_close($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 404) {
return false;
} else {
if ($tmp != false) {
return $tmp;
}
}
}
$url = $_GET['url'];
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
$f = getURL($url);
$isIcon = (strpos($url,'.ico')!== false) ? 'ico:' : '';
try{
$name = tempnam("/tmp", "imageProxy");
file_put_contents($name, $f);
$image = new Imagick($isIcon.$name);
print_r($image->getformat());
if($image->valid()){
$image->setImageFormat('png');
header("Content-Type: image/png");
echo $image;
}
} catch(exception $e){
echo $e;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment