Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote URL support added #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions aq_resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,33 @@ 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);

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;
}


// Check if $img_url is local.
if ( false === strpos( $url, $upload_url ) ) return false;

Expand Down