diff options
Diffstat (limited to 'include/photo/photo_driver.php')
-rw-r--r-- | include/photo/photo_driver.php | 99 |
1 files changed, 68 insertions, 31 deletions
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index f5e915402..e63125671 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -3,11 +3,24 @@ function photo_factory($data, $type = null) { $ph = null; - if(class_exists('Imagick')) { - require_once('include/photo/photo_imagick.php'); - $ph = new photo_imagick($data,$type); + $ignore_imagick = get_config('system', 'ignore_imagick'); + + if(class_exists('Imagick') && !$ignore_imagick) { + $v = Imagick::getVersion(); + preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); + if(version_compare($m[1],'6.6.7') >= 0) { + require_once('include/photo/photo_imagick.php'); + $ph = new photo_imagick($data,$type); + } + else { + // earlier imagick versions have issues with scaling png's + // don't log this because it will just fill the logfile. + // leave this note here so those who are looking for why + // we aren't using imagick can find it + } } - else { + + if(! $ph) { require_once('include/photo/photo_gd.php'); $ph = new photo_gd($data,$type); } @@ -287,6 +300,10 @@ abstract class photo_driver { $p['allow_gid'] = (($arr['allow_gid']) ? $arr['allow_gid'] : ''); $p['deny_cid'] = (($arr['deny_cid']) ? $arr['deny_cid'] : ''); $p['deny_gid'] = (($arr['deny_gid']) ? $arr['deny_gid'] : ''); + $p['created'] = (($arr['created']) ? $arr['created'] : datetime_convert()); + $p['edited'] = (($arr['edited']) ? $arr['edited'] : $p['created']); + $p['title'] = (($arr['title']) ? $arr['title'] : ''); + $p['description'] = (($arr['description']) ? $arr['description'] : ''); // temporary until we get rid of photo['profile'] and just use photo['photo_flags'] // but this will require updating all existing photos in the DB. @@ -318,28 +335,32 @@ abstract class photo_driver { `scale` = %d, `profile` = %d, `photo_flags` = %d, + `title` = '%s', + `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' - where id = %d limit 1", + where id = %d", intval($p['aid']), intval($p['uid']), dbesc($p['xchan']), dbesc($p['resource_id']), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc($p['created']), + dbesc($p['edited']), dbesc(basename($p['filename'])), dbesc($this->getType()), dbesc($p['album']), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($p['scale']), intval($p['profile']), intval($p['photo_flags']), + dbesc($p['title']), + dbesc($p['description']), dbesc($p['allow_cid']), dbesc($p['allow_gid']), dbesc($p['deny_cid']), @@ -349,24 +370,26 @@ abstract class photo_driver { } else { $r = q("INSERT INTO `photo` - ( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `photo_flags`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s' )", + ( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `photo_flags`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' )", intval($p['aid']), intval($p['uid']), dbesc($p['xchan']), dbesc($p['resource_id']), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc($p['created']), + dbesc($p['edited']), dbesc(basename($p['filename'])), dbesc($this->getType()), dbesc($p['album']), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($p['scale']), intval($p['profile']), intval($p['photo_flags']), + dbesc($p['title']), + dbesc($p['description']), dbesc($p['allow_cid']), dbesc($p['allow_gid']), dbesc($p['deny_cid']), @@ -405,7 +428,7 @@ abstract class photo_driver { `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' - where id = %d limit 1", + where id = %d", intval($aid), intval($uid), @@ -418,7 +441,7 @@ abstract class photo_driver { dbesc($album), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($scale), intval($profile), @@ -444,7 +467,7 @@ abstract class photo_driver { dbesc($album), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($scale), intval($profile), @@ -470,11 +493,11 @@ abstract class photo_driver { * Guess image mimetype from filename or from Content-Type header * * @arg $filename string Image filename - * @arg $fromcurl boolean Check Content-Type header from curl request + * @arg $headers string Headers to check for Content-Type (from curl request) */ function guess_image_type($filename, $headers = '') { - logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG); + logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG); $type = null; if ($headers) { $a = get_app(); @@ -484,21 +507,35 @@ function guess_image_type($filename, $headers = '') { list($k,$v) = array_map("trim", explode(":", trim($l), 2)); $hdrs[$k] = $v; } + logger('Curl headers: '.var_export($hdrs, true), LOGGER_DEBUG); if (array_key_exists('Content-Type', $hdrs)) $type = $hdrs['Content-Type']; } if (is_null($type)){ -// FIXME!!!! + + $ignore_imagick = get_config('system', 'ignore_imagick'); // Guessing from extension? Isn't that... dangerous? - if(class_exists('Imagick') && file_exists($filename) && is_readable($filename)) { - /** - * Well, this not much better, - * but at least it comes from the data inside the image, - * we won't be tricked by a manipulated extension - */ - $image = new Imagick($filename); - $type = $image->getImageMimeType(); - } else { + if(class_exists('Imagick') && file_exists($filename) && is_readable($filename) && !$ignore_imagick) { + $v = Imagick::getVersion(); + preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); + if(version_compare($m[1],'6.6.7') >= 0) { + /** + * Well, this not much better, + * but at least it comes from the data inside the image, + * we won't be tricked by a manipulated extension + */ + $image = new Imagick($filename); + $type = $image->getImageMimeType(); + } + else { + // earlier imagick versions have issues with scaling png's + // don't log this because it will just fill the logfile. + // leave this note here so those who are looking for why + // we aren't using imagick can find it + } + } + + if(is_null($type)) { $ext = pathinfo($filename, PATHINFO_EXTENSION); $ph = photo_factory(''); $types = $ph->supportedTypes(); @@ -525,7 +562,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { if($thing) $hash = photo_new_resource(); else { - $r = q("select resource_id from photo where xchan = '%s' and (photo_flags & %d ) and scale = 4 limit 1", + $r = q("select resource_id from photo where xchan = '%s' and (photo_flags & %d )>0 and scale = 4 limit 1", dbesc($xchan), intval(PHOTO_XCHAN) ); @@ -542,7 +579,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { if($photo) { $filename = basename($photo); - $type = guess_image_type($photo,true); + $type = guess_image_type($photo); if(! $type) $type = 'image/jpeg'; @@ -613,7 +650,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { $photo = $a->get_baseurl() . '/' . get_default_profile_photo(); $thumb = $a->get_baseurl() . '/' . get_default_profile_photo(80); $micro = $a->get_baseurl() . '/' . get_default_profile_photo(48); - $type = 'image/jpeg'; + $type = 'image/png'; } return(array($photo,$thumb,$micro,$type,$photo_failure)); |