summaryrefslogtreecommitdiff
path: root/proxy.php
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2023-07-22 14:41:14 -0400
committerlolcat <will@lolcat.ca>2023-07-22 14:41:14 -0400
commitbca265aea67ec62499aaa113a6490ce9ec7fe730 (patch)
tree3f05ec5ea542e41b474947e180034f42e99648e9 /proxy.php
still missing things on google scraper
Diffstat (limited to 'proxy.php')
-rw-r--r--proxy.php130
1 files changed, 130 insertions, 0 deletions
diff --git a/proxy.php b/proxy.php
new file mode 100644
index 0000000..edefd77
--- /dev/null
+++ b/proxy.php
@@ -0,0 +1,130 @@
+<?php
+
+include "lib/curlproxy.php";
+$proxy = new proxy();
+
+if(!isset($_GET["i"])){
+
+ header("X-Error: No URL(i) provided!");
+ $proxy->do404();
+ die();
+}
+
+try{
+
+ // original size request, stream file to browser
+ if(
+ !isset($_GET["s"]) ||
+ $_GET["s"] == "original"
+ ){
+
+ $proxy->stream_linear_image($_GET["i"]);
+ die();
+ }
+
+ // bing request, ask bing to resize and stream to browser
+ if(
+ preg_match(
+ '/bing.net$/',
+ parse_url($_GET["i"], PHP_URL_HOST)
+ )
+ ){
+
+ switch($_GET["s"]){
+
+ case "portrait": $req = "&w=50&h=90&p=0&qlt=99"; break;
+ case "landscape": $req = "&w=160&h=90&p=0&qlt=99"; break;
+ case "square": $req = "&w=90&h=90&p=0&qlt=99"; break;
+ case "thumb": $req = "&w=236&h=180&p=0&qlt=99"; break;
+ case "cover": $req = "&w=207&h=270&p=0&qlt=99"; break;
+ }
+
+ $proxy->stream_linear_image($_GET["i"] . $req, "https://bing.net");
+ die();
+ }
+
+ // resize image ourselves
+ $payload = $proxy->get($_GET["i"], $proxy::req_image, true);
+
+ // get image format & set imagick
+ $image = null;
+ $format = $proxy->getimageformat($payload, $image);
+
+ try{
+
+ if($format !== false){
+ $image->setFormat($format);
+ }
+
+ $image->readImageBlob($payload["body"]);
+ $image_width = $image->getImageWidth();
+ $image_height = $image->getImageHeight();
+
+ switch($_GET["s"]){
+
+ case "portrait":
+ $width = 50;
+ $height = 90;
+ break;
+
+ case "landscape":
+ $width = 160;
+ $height = 90;
+ break;
+
+ case "square":
+ $width = 90;
+ $height = 90;
+ break;
+
+ case "thumb":
+ $width = 236;
+ $height = 180;
+ break;
+
+ case "cover":
+ $width = 207;
+ $height = 270;
+ break;
+ }
+
+ $ratio = $image_width / $image_height;
+
+ if($image_width > $width){
+
+ $image_width = $width;
+ $image_height = round($image_width / $ratio);
+ }
+ if($image_height > $height){
+
+ $ratio = $image_width / $image_height;
+ $image_height = $height;
+ $image_width = $image_height * $ratio;
+ }
+
+ $image->setImageBackgroundColor(new ImagickPixel("#504945"));
+ $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
+
+ $image->resizeImage($image_width, $image_height, Imagick::FILTER_LANCZOS, 1);
+
+ $image->stripImage();
+ $image->setFormat("jpeg");
+ $image->setImageCompression(Imagick::COMPRESSION_JPEG2000);
+
+ $proxy->getfilenameheader($payload["headers"], $_GET["i"]);
+
+ header("Content-Type: image/jpeg");
+ echo $image->getImageBlob();
+
+ }catch(ImagickException $error){
+
+ header("X-Error: Could not convert the image: (" . $error->getMessage() . ")");
+ $proxy->do404();
+ }
+
+}catch(Exception $error){
+
+ header("X-Error: " . $error->getMessage());
+ $proxy->do404();
+ die();
+}