From eb1f2358abab2c9791cd04f8872efb98582e0d5d Mon Sep 17 00:00:00 2001 From: Ruben Harms Date: Tue, 28 Oct 2014 14:42:14 +0100 Subject: [PATCH 1/2] Remote URL support added! Possibility to use remote URL's added. --- aq_resizer.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/aq_resizer.php b/aq_resizer.php index 9f0ff88..5afe69f 100644 --- a/aq_resizer.php +++ b/aq_resizer.php @@ -69,13 +69,36 @@ public function process( $url, $width = null, $height = null, $crop = null, $sin $http_prefix = "http://"; $https_prefix = "https://"; - /* if the $url scheme differs from $upload_url scheme, make them match - if the schemes differe, images don't show up. */ - if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well - $upload_url = str_replace($http_prefix,$https_prefix,$upload_url); + if ( false !== strpos( $url, $upload_url ) ){ + /* if the $url scheme differs from $upload_url scheme, make them match + if the schemes differe, images don't show up. */ + if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well + $upload_url = str_replace($http_prefix,$https_prefix,$upload_url); + } + elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well + $upload_url = str_replace($https_prefix,$http_prefix,$upload_url); + } } - elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well - $upload_url = str_replace($https_prefix,$http_prefix,$upload_url); + + /** + * Library kan nu ook omgaan met remote afbeeldingen! + * + * @author Ruben Harms + */ + if ( false === strpos( $url, $upload_url ) ){ + $pinfo = pathinfo($url); + $ext = $pinfo['extension']; + if (stristr($ext,"?")) list($ext,$qs) = explode("?",$ext); + $md5_filename = md5($url). '.'. $ext; + + $md5_path = $upload_dir . '/'.$md5_filename; + $md5_url = $upload_url . '/'.$md5_filename; + + if (!file_exists($md5_path)){ + $tmp_img = file_get_contents($url); + file_put_contents($md5_path,$tmp_img); + } + $url = $md5_url; } From 097045087197de6e46b8453e9abfcec9179f2686 Mon Sep 17 00:00:00 2001 From: Ruben Harms Date: Tue, 28 Oct 2014 14:43:00 +0100 Subject: [PATCH 2/2] Removed comments Removed comments --- aq_resizer.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/aq_resizer.php b/aq_resizer.php index 5afe69f..c243284 100644 --- a/aq_resizer.php +++ b/aq_resizer.php @@ -80,11 +80,6 @@ public function process( $url, $width = null, $height = null, $crop = null, $sin } } - /** - * Library kan nu ook omgaan met remote afbeeldingen! - * - * @author Ruben Harms - */ if ( false === strpos( $url, $upload_url ) ){ $pinfo = pathinfo($url); $ext = $pinfo['extension']; @@ -101,7 +96,6 @@ public function process( $url, $width = null, $height = null, $crop = null, $sin $url = $md5_url; } - // Check if $img_url is local. if ( false === strpos( $url, $upload_url ) ) return false;