Skip to content

Instantly share code, notes, and snippets.

@trentwiles
Created July 8, 2020 12:33
Show Gist options
  • Save trentwiles/29b618e7170c65627cabab7cafff729a to your computer and use it in GitHub Desktop.
Save trentwiles/29b618e7170c65627cabab7cafff729a to your computer and use it in GitHub Desktop.
Image Proxy
<?php
/*
Image proxy in the works.
*/
$image = $_GET['url'];
$path = $image;
$ext = pathinfo($path, PATHINFO_EXTENSION);
$deny = array("jpg", "png", "gif", "jpeg", "bmp", "ico");
if(in_array($ext,$deny)){
header("Content-type: image/${ext}");
echo file_get_contents($image);
}else{
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 0 );
$text_colour = imagecolorallocate( $my_img, 225, 225, 225 );
imagestring( $my_img, 4, 30, 25, "Invalid File Type", $text_colour );
imagesetthickness ( $my_img, 5 );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
}
@youngchief-btw
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment