diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Photo.php | 107 | ||||
-rw-r--r-- | include/network.php | 50 |
2 files changed, 132 insertions, 25 deletions
diff --git a/include/Photo.php b/include/Photo.php index 8daac450e..5882f39f5 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -1,6 +1,111 @@ <?php /** @file */ +abstract class photo_driver { + + private $image; + private $width; + private $height; + private $valid; + private $type; + private $types; + + + abstract function supportedTypes(); + abstract function load(); + abstract function destroy(); + abstract function getWidth(); + abstract function getHeight(); + + abstract function getImage(); + + abstract function getType(); + + abstract function getExt(); + + abstract function scaleImage($max); + + abstract function rotate($degrees); + + abstract function flip($horiz = true, $vert = false); + + abstract function scaleImageUp($min); + + abstract function scaleImageSquare($dim); + + abstract function cropImage($max,$x,$y,$w,$h); + + abstract function imageString(); + + public function saveImage($path) { + if(!$this->is_valid()) + return FALSE; + file_put_contents($path, $this->imageString()); + } + + public function orient($filename) { + + /** + * This function is a bit unusual, because it is operating on a file, but you must + * first create an image from that file to initialise the type and check validity + * of the image. + */ + + if(! $this->is_valid()) + return FALSE; + + if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) + return; + + $exif = @exif_read_data($filename); + if($exif) { + $ort = $exif['Orientation']; + + switch($ort) + { + case 1: // nothing + break; + + case 2: // horizontal flip + $this->flip(); + break; + + case 3: // 180 rotate left + $this->rotate(180); + break; + + case 4: // vertical flip + $this->flip(false, true); + break; + + case 5: // vertical flip + 90 rotate right + $this->flip(false, true); + $this->rotate(-90); + break; + + case 6: // 90 rotate right + $this->rotate(-90); + break; + + case 7: // horizontal flip + 90 rotate right + $this->flip(); + $this->rotate(-90); + break; + + case 8: // 90 rotate left + $this->rotate(90); + break; + } + } + } +} + + + + + + + class Photo { private $image; @@ -512,10 +617,12 @@ class Photo { imagepng($this->image,NULL, $quality); break; case "image/jpeg": + default: $quality = get_config('system','jpeg_quality'); if((! $quality) || ($quality > 100)) $quality = JPEG_QUALITY; imagejpeg($this->image,NULL,$quality); + break; } $string = ob_get_contents(); ob_end_clean(); diff --git a/include/network.php b/include/network.php index d3e6480d6..a70207be2 100644 --- a/include/network.php +++ b/include/network.php @@ -321,7 +321,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { -function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0) { +function z_post_url($url,$params, $redirects = 0, $opts = array()) { $ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => ""); @@ -336,28 +336,28 @@ function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0) curl_setopt($ch, CURLOPT_POSTFIELDS,$params); curl_setopt($ch, CURLOPT_USERAGENT, "Red"); - if(intval($timeout)) { - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + + if (x($opts,'accept_content')){ + curl_setopt($ch,CURLOPT_HTTPHEADER, array ( + "Accept: " . $opts['accept_content'] + )); + } + + if(x($opts,'timeout') && intval($opts['timeout'])) { + @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { $curl_time = intval(get_config('system','curl_timeout')); - curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); + @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } - if(defined('LIGHTTPD')) { - if(!is_array($headers)) { - $headers = array('Expect:'); - } else { - if(!in_array('Expect:', $headers)) { - array_push($headers, 'Expect:'); - } - } + if(x($opts,'http_auth')) { + // "username" . ':' . "password" + @curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']); } - if($headers) - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, + ((x($opts,'novalidate') && intval($opts['novalidate'])) ? false : true)); $prx = get_config('system','proxy'); if(strlen($prx)) { @@ -398,9 +398,9 @@ function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0) if (isset($url_parsed)) { curl_close($ch); if($http_code == 303) { - return z_fetch_url($newurl,false,$headers,$redirects++,$timeout); + return z_fetch_url($newurl,false,$redirects++,$opts); } else { - return z_post_url($newurl,$params,$headers,$redirects++,$timeout); + return z_post_url($newurl,$params,$redirects++,$opts); } } } @@ -447,22 +447,22 @@ function xml_status($st, $message = '') { * Send HTTP status header and exit * @param int $val * integer HTTP status result value - * + * @param string $msg + * optional message * @returns (does not return, process is terminated) */ -function http_status_exit($val) { +function http_status_exit($val,$msg = '') { $err = ''; if($val >= 400) - $err = 'Error'; + $msg = (($msg) ? $msg : 'Error'); if($val >= 200 && $val < 300) - $err = 'OK'; + $msg = (($msg) ? $msg : 'OK'); - logger('http_status_exit ' . $val); - header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); + logger('http_status_exit ' . $val . ' ' . $msg); + header($_SERVER['SERVER_PROTOCOL'] . ' ' . $val . ' ' . $msg); killme(); - } |