use Friendica\Core\NotificationsManager;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
+use Friendica\Model\Photo;
use Friendica\Model\User;
use Friendica\Network\FKOAuth1;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Network\HTTPException\TooManyRequestsException;
use Friendica\Object\Contact;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
use Friendica\Protocol\Diaspora;
use Friendica\Util\XML;
api_user()
);
if (DBM::is_result($r)) {
- $phototypes = Photo::supportedTypes();
+ $phototypes = Image::supportedTypes();
$ext = $phototypes[$r[0]['type']];
$_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
$_REQUEST['body'] .= '[img]' . System::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . '[/img][/url]';
$attachments = array();
foreach ($images[1] as $image) {
- $imagedata = Photo::getInfoFromURL($image);
+ $imagedata = Image::getInfoFromURL($image);
if ($imagedata) {
$attachments[] = array("url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]);
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
- $image = Photo::getInfoFromURL($url);
+ $image = Image::getInfoFromURL($url);
if ($image) {
// If image cache is activated, then use the following sizes:
// thumb (150), small (340), medium (600) and large (1024)
$media_url = proxy_url($url);
$sizes = array();
- $scale = Photo::scaleImageTo($image[0], $image[1], 150);
+ $scale = Image::getScalingDimensions($image[0], $image[1], 150);
$sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
if (($image[0] > 150) || ($image[1] > 150)) {
- $scale = Photo::scaleImageTo($image[0], $image[1], 340);
+ $scale = Image::getScalingDimensions($image[0], $image[1], 340);
$sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
}
- $scale = Photo::scaleImageTo($image[0], $image[1], 600);
+ $scale = Image::getScalingDimensions($image[0], $image[1], 600);
$sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
if (($image[0] > 600) || ($image[1] > 600)) {
- $scale = Photo::scaleImageTo($image[0], $image[1], 1024);
+ $scale = Image::getScalingDimensions($image[0], $image[1], 1024);
$sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
}
} else {
}
if ($filetype == "") {
- $filetype=Photo::guessImageType($filename);
+ $filetype=Image::guessType($filename);
}
$imagedata = getimagesize($src);
if ($imagedata) {
// create Photo instance with the data of the image
$imagedata = @file_get_contents($src);
- $ph = new Photo($imagedata, $filetype);
- if (! $ph->isValid()) {
+ $Image = new Image($imagedata, $filetype);
+ if (! $Image->isValid()) {
throw new InternalServerErrorException("unable to process image data");
}
// check orientation of image
- $ph->orient($src);
+ $Image->orient($src);
@unlink($src);
// check max length of images on server
$max_length = MAX_IMAGE_LENGTH;
}
if ($max_length > 0) {
- $ph->scaleImage($max_length);
+ $Image->scaleDown($max_length);
logger("File upload: Scaling picture to new size " . $max_length, LOGGER_DEBUG);
}
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
// create a new resource-id if not already provided
$hash = ($photo_id == null) ? photo_new_resource() : $photo_id;
// upload normal image (scales 0, 1, 2)
logger("photo upload: starting new photo upload", LOGGER_DEBUG);
- $r =$ph->store(local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: image upload with scale 0 (original size) failed");
}
if ($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $Image->scaleDown(640);
+ $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: image upload with scale 1 (640x640) failed");
}
}
if ($width > 320 || $height > 320) {
- $ph->scaleImage(320);
- $r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $Image->scaleDown(320);
+ $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: image upload with scale 2 (320x320) failed");
}
logger("photo upload: starting new profile image upload", LOGGER_DEBUG);
if ($width > 175 || $height > 175) {
- $ph->scaleImage(175);
- $r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $Image->scaleDown(175);
+ $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: profile image upload with scale 4 (175x175) failed");
}
}
if ($width > 80 || $height > 80) {
- $ph->scaleImage(80);
- $r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $Image->scaleDown(80);
+ $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: profile image upload with scale 5 (80x80) failed");
}
}
if ($width > 48 || $height > 48) {
- $ph->scaleImage(48);
- $r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $Image->scaleDown(48);
+ $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: profile image upload with scale 6 (48x48) failed");
}
}
- $ph->__destruct();
+ $Image->__destruct();
logger("photo upload: new profile image upload ended", LOGGER_DEBUG);
}
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Object\Contact;
+use Friendica\Object\Image;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus;
-use Friendica\Util\Lock;
require_once 'include/bbcode.php';
require_once 'include/oembed.php';
$width = intval($match[1]);
$height = intval($match[2]);
- $ph = new Photo($data, $type);
- if ($ph->isValid()) {
- $ph->scaleImage(max($width, $height));
- $data = $ph->imageString();
- $type = $ph->getType();
+ $Image = new Image($data, $type);
+ if ($Image->isValid()) {
+ $Image->scaleDown(max($width, $height));
+ $data = $Image->asString();
+ $type = $Image->getType();
}
}
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Probe;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
use Friendica\Util\XML;
/**
}
// guess mimetype from headers or filename
- $type = Photo::guessImageType($mtch[1], true);
+ $type = Image::guessType($mtch[1], true);
if ($i) {
- $ph = new Photo($i, $type);
- if ($ph->isValid()) {
- $orig_width = $ph->getWidth();
- $orig_height = $ph->getHeight();
+ $Image = new Image($i, $type);
+ if ($Image->isValid()) {
+ $orig_width = $Image->getWidth();
+ $orig_height = $Image->getHeight();
if ($orig_width > 640 || $orig_height > 640) {
- $ph->scaleImage(640);
- $new_width = $ph->getWidth();
- $new_height = $ph->getHeight();
+ $Image->scaleDown(640);
+ $new_width = $Image->getWidth();
+ $new_height = $Image->getHeight();
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
$s = str_replace(
$mtch[0],
use Friendica\App;
use Friendica\ParseUrl;
use Friendica\Core\PConfig;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
require_once "include/bbcode.php";
require_once "include/html2plain.php";
if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches)) {
- $picturedata = Photo::getInfoFromURL($matches[1]);
+ $picturedata = Image::getInfoFromURL($matches[1]);
if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1]))
$post["image"] = $matches[1];
$post["preview"] = $pictures[0][2];
$post["text"] = str_replace($pictures[0][0], "", $body);
} else {
- $imgdata = Photo::getInfoFromURL($pictures[0][1]);
+ $imgdata = Image::getInfoFromURL($pictures[0][1]);
if (substr($imgdata["mime"], 0, 6) == "image/") {
$post["type"] = "photo";
$post["image"] = $pictures[0][1];
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Model\Photo;
+use Friendica\Object\Image;
define("IMPORT_DEBUG", False);
$photo['uid'] = $newuid;
$photo['data'] = hex2bin($photo['data']);
- $p = new Photo($photo['data'], $photo['type']);
- $r = $p->store(
+ $Image = new Image($photo['data'], $photo['type']);
+ $r = Photo::store(
+ $Image,
$photo['uid'], $photo['contact-id'], //0
$photo['resource-id'], $photo['filename'], $photo['album'], $photo['scale'], $photo['profile'], //1
$photo['allow_cid'], $photo['allow_gid'], $photo['deny_cid'], $photo['deny_gid']
use Friendica\App;
use Friendica\Core\System;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
/**
* @param App $a
function _map_files1($rr){
$a = get_app();
- $types = Photo::supportedTypes();
+ $types = Image::supportedTypes();
$ext = $types[$rr['type']];
$filename_e = $rr['filename'];
use Friendica\App;
use Friendica\Core\System;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
$install_wizard_pass = 1;
if (class_exists('Imagick')) {
$imagick = true;
- $supported = Photo::supportedTypes();
+ $supported = Image::supportedTypes();
if (array_key_exists('image/gif', $supported)) {
$gif = true;
}
*/
use Friendica\App;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
require_once 'include/security.php';
$uid = str_replace(array('.jpg', '.png', '.gif'), array('', '', ''), $person);
- foreach (Photo::supportedTypes() AS $m => $e) {
+ foreach (Image::supportedTypes() AS $m => $e) {
$uid = str_replace('.'.$e, '', $uid);
}
$resolution = 0;
$photo = str_replace(array('.jpg', '.png', '.gif'), array('', '', ''), $photo);
- foreach (Photo::supportedTypes() AS $m => $e) {
+ foreach (Image::supportedTypes() AS $m => $e) {
$photo = str_replace('.'.$e, '', $photo);
}
}
// Resize only if its not a GIF and it is supported by the library
- if (($mimetype != "image/gif") && in_array($mimetype, Photo::supportedTypes())) {
- $ph = new Photo($data, $mimetype);
- if ($ph->isValid()) {
+ if (($mimetype != "image/gif") && in_array($mimetype, Image::supportedTypes())) {
+ $Image = new Image($data, $mimetype);
+ if ($Image->isValid()) {
if (isset($customres) && $customres > 0 && $customres < 500) {
- $ph->scaleImageSquare($customres);
+ $Image->scaleToSquare($customres);
}
- $data = $ph->imageString();
- $mimetype = $ph->getType();
+ $data = $Image->asString();
+ $mimetype = $Image->getType();
}
}
use Friendica\Core\Config;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
+use Friendica\Model\Photo;
use Friendica\Network\Probe;
use Friendica\Object\Contact;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
require_once 'include/photos.php';
require_once 'include/items.php';
logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
- $phototypes = Photo::supportedTypes();
+ $phototypes = Image::supportedTypes();
$can_post = false;
$visitor = 0;
intval($page_owner_uid)
);
if (DBM::is_result($r)) {
- $ph = new Photo($r[0]['data'], $r[0]['type']);
- if ($ph->isValid()) {
+ $Image = new Image($r[0]['data'], $r[0]['type']);
+ if ($Image->isValid()) {
$rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
- $ph->rotate($rotate_deg);
+ $Image->rotate($rotate_deg);
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
$x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
- dbesc($ph->imageString()),
+ dbesc($Image->asString()),
intval($height),
intval($width),
dbesc($resource_id),
);
if ($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $Image->scaleDown(640);
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
$x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
- dbesc($ph->imageString()),
+ dbesc($Image->asString()),
intval($height),
intval($width),
dbesc($resource_id),
}
if ($width > 320 || $height > 320) {
- $ph->scaleImage(320);
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $Image->scaleDown(320);
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
$x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
- dbesc($ph->imageString()),
+ dbesc($Image->asString()),
intval($height),
intval($width),
dbesc($resource_id),
$type = $_FILES['userfile']['type'];
}
if ($type == "") {
- $type = Photo::guessImageType($filename);
+ $type = Image::guessType($filename);
}
logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
$imagedata = @file_get_contents($src);
- $ph = new Photo($imagedata, $type);
+ $Image = new Image($imagedata, $type);
- if (! $ph->isValid()) {
+ if (! $Image->isValid()) {
logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
notice( t('Unable to process image.') . EOL );
@unlink($src);
killme();
}
- $exif = $ph->orient($src);
+ $exif = $Image->orient($src);
@unlink($src);
$max_length = Config::get('system', 'max_image_length');
$max_length = MAX_IMAGE_LENGTH;
}
if ($max_length > 0) {
- $ph->scaleImage($max_length);
+ $Image->scaleDown($max_length);
}
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
$smallest = 0;
$photo_hash = photo_new_resource();
- $r = $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $r = Photo::store($Image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
if (! $r) {
logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
}
if ($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $Image->scaleDown(640);
+ Photo::store($Image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 1;
}
if ($width > 320 || $height > 320) {
- $ph->scaleImage(320);
- $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $Image->scaleDown(320);
+ Photo::store($Image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 2;
}
$arr['origin'] = 1;
$arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
- . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
+ . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
. '[/url]';
$item_id = item_store($arr);
return;
}
- $phototypes = Photo::supportedTypes();
+ $phototypes = Image::supportedTypes();
$_SESSION['photo_return'] = $a->cmd;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Model\Photo;
+use Friendica\Object\Image;
function profile_photo_init(App $a) {
$base_image = $r[0];
- $im = new Photo($base_image['data'], $base_image['type']);
- if ($im->isValid()) {
- $im->cropImage(175,$srcX,$srcY,$srcW,$srcH);
+ $Image = new Image($base_image['data'], $base_image['type']);
+ if ($Image->isValid()) {
+ $Image->crop(175,$srcX,$srcY,$srcW,$srcH);
- $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile);
+ $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile);
if ($r === false) {
notice ( sprintf(t('Image size reduction [%s] failed.'),"175") . EOL );
}
- $im->scaleImage(80);
+ $Image->scaleDown(80);
- $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, $is_default_profile);
+ $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, $is_default_profile);
if ($r === false) {
notice( sprintf(t('Image size reduction [%s] failed.'),"80") . EOL );
}
- $im->scaleImage(48);
+ $Image->scaleDown(48);
- $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 6, $is_default_profile);
+ $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 6, $is_default_profile);
if ($r === false) {
notice( sprintf(t('Image size reduction [%s] failed.'),"48") . EOL );
);
$r = q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `self` AND `uid` = %d",
- dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-4.' . $im->getExt()),
- dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-5.' . $im->getExt()),
- dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-6.' . $im->getExt()),
+ dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-4.' . $Image->getExt()),
+ dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-5.' . $Image->getExt()),
+ dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-6.' . $Image->getExt()),
intval(local_user())
);
} else {
$r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d",
- dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-4.' . $im->getExt()),
- dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-5.' . $im->getExt()),
+ dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-4.' . $Image->getExt()),
+ dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-5.' . $Image->getExt()),
intval($_REQUEST['profile']),
intval(local_user())
);
$filesize = intval($_FILES['userfile']['size']);
$filetype = $_FILES['userfile']['type'];
if ($filetype == "") {
- $filetype = Photo::guessImageType($filename);
+ $filetype = Image::guessType($filename);
}
$maximagesize = Config::get('system', 'maximagesize');
}
$imagedata = @file_get_contents($src);
- $ph = new Photo($imagedata, $filetype);
+ $ph = new Image($imagedata, $filetype);
if (! $ph->isValid()) {
notice(t('Unable to process image.') . EOL);
goaway(System::baseUrl() . '/profiles');
return; // NOTREACHED
}
- $ph = new Photo($r[0]['data'], $r[0]['type']);
+ $ph = new Image($r[0]['data'], $r[0]['type']);
profile_photo_crop_ui_head($a, $ph);
// go ahead as we have jus uploaded a new photo to crop
}
if(! function_exists('profile_photo_crop_ui_head')) {
-function profile_photo_crop_ui_head(App $a, $ph) {
+function profile_photo_crop_ui_head(App $a, Image $Image) {
$max_length = Config::get('system','max_image_length');
if (! $max_length) {
$max_length = MAX_IMAGE_LENGTH;
}
if ($max_length > 0) {
- $ph->scaleImage($max_length);
+ $Image->scaleDown($max_length);
}
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
if ($width < 175 || $height < 175) {
- $ph->scaleImageUp(200);
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $Image->scaleUp(200);
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
}
$hash = photo_new_resource();
$smallest = 0;
- $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 );
+ $r = Photo::store($Image, local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 );
if ($r) {
info( t('Image uploaded successfully.') . EOL );
}
if ($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 );
+ $Image->scaleDown(640);
+ $r = Photo::store($Image, local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 );
if ($r === false) {
notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL );
$a->config['imagecrop'] = $hash;
$a->config['imagecrop_resolution'] = $smallest;
- $a->config['imagecrop_ext'] = $ph->getExt();
+ $a->config['imagecrop_ext'] = $Image->getExt();
$a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array());
$a->page['end'] .= replace_macros(get_markup_template("cropend.tpl"), array());
return;
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Model\Photo;
+use Friendica\Object\Image;
define('PROXY_DEFAULT_TIME', 86400); // 1 Day
// reduce quality - if it isn't a GIF
if ($mime != 'image/gif') {
- $img = new Photo($img_str, $mime);
- if ($img->isValid()) {
- $img_str = $img->imageString();
+ $Image = new Image($img_str, $mime);
+ if ($Image->isValid()) {
+ $img_str = $Image->asString();
}
}
$mime = 'image/png';
$cachefile = ''; // Clear the cachefile so that the dummy isn't stored
$valid = false;
- $img = new Photo($img_str, 'image/png');
- if ($img->isValid()) {
- $img->scaleImage(10);
- $img_str = $img->imageString();
+ $Image = new Image($img_str, 'image/png');
+ if ($Image->isValid()) {
+ $Image->scaleDown(10);
+ $img_str = $Image->asString();
}
} elseif ($mime != 'image/jpeg' && !$direct_cache && $cachefile == '') {
$image = @imagecreatefromstring($img_str);
'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '', 'desc' => $mime);
dba::insert('photo', $fields);
} else {
- $img = new Photo($img_str, $mime);
- if ($img->isValid() && !$direct_cache && ($cachefile == '')) {
- $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
+ $Image = new Image($img_str, $mime);
+ if ($Image->isValid() && !$direct_cache && ($cachefile == '')) {
+ Photo::store($Image, 0, 0, $urlhash, $_REQUEST['url'], '', 100);
}
}
}
// reduce quality - if it isn't a GIF
if ($mime != 'image/gif') {
- $img = new Photo($img_str, $mime);
- if ($img->isValid()) {
- $img->scaleImage($size);
- $img_str = $img->imageString();
+ $Image = new Image($img_str, $mime);
+ if ($Image->isValid()) {
+ $Image->scaleDown($size);
+ $img_str = $Image->asString();
}
}
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Model\Photo;
+use Friendica\Object\Image;
function wall_upload_post(App $a, $desktopmode = true) {
$filetype = "";
}
- if ($filetype=="") {
- $filetype=Photo::guessImageType($filename);
+ if ($filetype == "") {
+ $filetype = Image::guessType($filename);
}
// If there is a temp name, then do a manual check
}
$imagedata = @file_get_contents($src);
- $ph = new Photo($imagedata, $filetype);
+ $Image = new Image($imagedata, $filetype);
- if (! $ph->isValid()) {
+ if (! $Image->isValid()) {
$msg = t('Unable to process image.');
if ($r_json) {
echo json_encode(array('error'=>$msg));
killme();
}
- $ph->orient($src);
+ $Image->orient($src);
@unlink($src);
$max_length = Config::get('system', 'max_image_length');
$max_length = MAX_IMAGE_LENGTH;
}
if ($max_length > 0) {
- $ph->scaleImage($max_length);
+ $Image->scaleDown($max_length);
logger("File upload: Scaling picture to new size " . $max_length, LOGGER_DEBUG);
}
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
$hash = photo_new_resource();
$defperm = '<' . $default_cid . '>';
- $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm);
+ $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm);
if (! $r) {
$msg = t('Image upload failed.');
}
if ($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 1, 0, $defperm);
+ $Image->scaleDown(640);
+ $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 1, 0, $defperm);
if ($r) {
$smallest = 1;
}
}
if ($width > 320 || $height > 320) {
- $ph->scaleImage(320);
- $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 2, 0, $defperm);
+ $Image->scaleDown(320);
+ $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 2, 0, $defperm);
if ($r && ($smallest == 0)) {
$smallest = 2;
}
$picture["height"] = $r[0]["height"];
$picture["type"] = $r[0]["type"];
$picture["albumpage"] = System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash;
- $picture["picture"] = System::baseUrl() . "/photo/{$hash}-0." . $ph->getExt();
- $picture["preview"] = System::baseUrl() . "/photo/{$hash}-{$smallest}." . $ph->getExt();
+ $picture["picture"] = System::baseUrl() . "/photo/{$hash}-0." . $Image->getExt();
+ $picture["preview"] = System::baseUrl() . "/photo/{$hash}-{$smallest}." . $Image->getExt();
if ($r_json) {
echo json_encode(array('picture'=>$picture));
/* mod Waitman Gobble NO WARRANTY */
// if we get the signal then return the image url info in BBCODE
if ($_REQUEST['hush']!='yeah') {
- echo "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . System::baseUrl() . "/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]\n\n";
+ echo "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . System::baseUrl() . "/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n";
} else {
- $m = '[url='.System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash.'][img]'.System::baseUrl()."/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]";
+ $m = '[url='.System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash.'][img]'.System::baseUrl()."/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]";
return($m);
}
/* mod Waitman Gobble NO WARRANTY */
--- /dev/null
+<?php
+
+/**
+ * @file src/Model/Photo.php
+ * @brief This file contains the Photo class for database interface
+ */
+
+namespace Friendica\Model;
+
+use Friendica\Core\System;
+use Friendica\Database\DBM;
+use Friendica\Object\Image;
+use dba;
+
+require_once "include/photos.php";
+/**
+ * Class to handle photo dabatase table
+ */
+class Photo
+{
+ /**
+ * @param integer $uid uid
+ * @param integer $cid cid
+ * @param integer $rid rid
+ * @param string $filename filename
+ * @param string $album album name
+ * @param integer $scale scale
+ * @param integer $profile optional, default = 0
+ * @param string $allow_cid optional, default = ''
+ * @param string $allow_gid optional, default = ''
+ * @param string $deny_cid optional, default = ''
+ * @param string $deny_gid optional, default = ''
+ * @param string $desc optional, default = ''
+ * @return object
+ */
+ public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
+ {
+ $r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
+ if (DBM::is_result($r)) {
+ $guid = $r['guid'];
+ } else {
+ $guid = get_guid();
+ }
+
+ $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1));
+
+ $fields = array(
+ 'uid' => $uid,
+ 'contact-id' => $cid,
+ 'guid' => $guid,
+ 'resource-id' => $rid,
+ 'created' => datetime_convert(),
+ 'edited' => datetime_convert(),
+ 'filename' => basename($filename),
+ 'type' => $Image->getType(),
+ 'album' => $album,
+ 'height' => $Image->getHeight(),
+ 'width' => $Image->getWidth(),
+ 'datasize' => strlen($Image->asString()),
+ 'data' => $Image->asString(),
+ 'scale' => $scale,
+ 'profile' => $profile,
+ 'allow_cid' => $allow_cid,
+ 'allow_gid' => $allow_gid,
+ 'deny_cid' => $deny_cid,
+ 'deny_gid' => $deny_gid,
+ 'desc' => $desc
+ );
+
+ if (DBM::is_result($x)) {
+ $r = dba::update('photo', $fields, array('id' => $x['id']));
+ } else {
+ $r = dba::insert('photo', $fields);
+ }
+
+ return $r;
+ }
+
+ /**
+ * @param string $photo photo
+ * @param integer $uid user id
+ * @param integer $cid contact id
+ * @param boolean $quit_on_error optional, default false
+ * @return array
+ */
+ public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
+ {
+ $r = dba::select(
+ 'photo', array('resource-id'), array('uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos'), array('limit' => 1)
+ );
+
+ if (DBM::is_result($r) && strlen($r['resource-id'])) {
+ $hash = $r['resource-id'];
+ } else {
+ $hash = photo_new_resource();
+ }
+
+ $photo_failure = false;
+
+ $filename = basename($photo);
+ $img_str = fetch_url($photo, true);
+
+ if ($quit_on_error && ($img_str == "")) {
+ return false;
+ }
+
+ $type = Image::guessType($photo, true);
+ $Image = new Image($img_str, $type);
+ if ($Image->isValid()) {
+ $Image->scaleToSquare(175);
+
+ $r = self::store($Image, $uid, $cid, $hash, $filename, 'Contact Photos', 4);
+
+ if ($r === false) {
+ $photo_failure = true;
+ }
+
+ $Image->scaleDown(80);
+
+ $r = self::store($Image, $uid, $cid, $hash, $filename, 'Contact Photos', 5);
+
+ if ($r === false) {
+ $photo_failure = true;
+ }
+
+ $Image->scaleDown(48);
+
+ $r = self::store($Image, $uid, $cid, $hash, $filename, 'Contact Photos', 6);
+
+ if ($r === false) {
+ $photo_failure = true;
+ }
+
+ $suffix = '?ts=' . time();
+
+ $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $Image->getExt() . $suffix;
+ $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $Image->getExt() . $suffix;
+ $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $Image->getExt() . $suffix;
+
+ // Remove the cached photo
+ $a = get_app();
+ $basepath = $a->get_basepath();
+
+ if (is_dir($basepath . "/photo")) {
+ $filename = $basepath . '/photo/' . $hash . '-4.' . $Image->getExt();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+ $filename = $basepath . '/photo/' . $hash . '-5.' . $Image->getExt();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+ $filename = $basepath . '/photo/' . $hash . '-6.' . $Image->getExt();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+ }
+ } else {
+ $photo_failure = true;
+ }
+
+ if ($photo_failure && $quit_on_error) {
+ return false;
+ }
+
+ if ($photo_failure) {
+ $photo = System::baseUrl() . '/images/person-175.jpg';
+ $thumb = System::baseUrl() . '/images/person-80.jpg';
+ $micro = System::baseUrl() . '/images/person-48.jpg';
+ }
+
+ return array($photo, $thumb, $micro);
+ }
+}
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
+use Friendica\Model\Photo;
use Friendica\Object\Contact;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
use dba;
require_once 'boot.php';
$filename = basename($photo);
$img_str = fetch_url($photo, true);
// guess mimetype from headers or filename
- $type = Photo::guessImageType($photo, true);
+ $type = Image::guessType($photo, true);
- $img = new Photo($img_str, $type);
- if ($img->isValid()) {
- $img->scaleImageSquare(175);
+ $Image = new Image($img_str, $type);
+ if ($Image->isValid()) {
+ $Image->scaleToSquare(175);
$hash = photo_new_resource();
- $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4);
+ $r = Photo::store($Image, $newuid, 0, $hash, $filename, t('Profile Photos'), 4);
if ($r === false) {
$photo_failure = true;
}
- $img->scaleImage(80);
+ $Image->scaleDown(80);
- $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5);
+ $r = Photo::store($Image, $newuid, 0, $hash, $filename, t('Profile Photos'), 5);
if ($r === false) {
$photo_failure = true;
}
- $img->scaleImage(48);
+ $Image->scaleDown(48);
- $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6);
+ $r = Photo::store($Image, $newuid, 0, $hash, $filename, t('Profile Photos'), 6);
if ($r === false) {
$photo_failure = true;
--- /dev/null
+<?php
+/**
+ * @file src/Object/Image.php
+ * @brief This file contains the Image class for image processing
+ */
+namespace Friendica\Object;
+
+use Friendica\App;
+use Friendica\Core\Cache;
+use Friendica\Core\Config;
+use Friendica\Core\System;
+use Friendica\Database\DBM;
+use Friendica\Model\Photo;
+use Exception;
+use Imagick;
+use ImagickPixel;
+
+require_once "include/photos.php";
+
+/**
+ * Class to handle images
+ */
+class Image
+{
+ private $image;
+
+ /*
+ * Put back gd stuff, not everybody have Imagick
+ */
+ private $imagick;
+ private $width;
+ private $height;
+ private $valid;
+ private $type;
+ private $types;
+
+ /**
+ * @brief supported mimetypes and corresponding file extensions
+ * @return array
+ */
+ public static function supportedTypes()
+ {
+ if (class_exists('Imagick')) {
+ // Imagick::queryFormats won't help us a lot there...
+ // At least, not yet, other parts of friendica uses this array
+ $t = array(
+ 'image/jpeg' => 'jpg',
+ 'image/png' => 'png',
+ 'image/gif' => 'gif'
+ );
+ } else {
+ $t = array();
+ $t['image/jpeg'] ='jpg';
+ if (imagetypes() & IMG_PNG) {
+ $t['image/png'] = 'png';
+ }
+ }
+
+ return $t;
+ }
+
+ /**
+ * @brief Constructor
+ * @param object $data data
+ * @param boolean $type optional, default null
+ * @return object
+ */
+ public function __construct($data, $type = null)
+ {
+ $this->imagick = class_exists('Imagick');
+ $this->types = static::supportedTypes();
+ if (!array_key_exists($type, $this->types)) {
+ $type='image/jpeg';
+ }
+ $this->type = $type;
+
+ if ($this->isImagick() && $this->loadData($data)) {
+ return true;
+ } else {
+ // Failed to load with Imagick, fallback
+ $this->imagick = false;
+ }
+ return $this->loadData($data);
+ }
+
+ /**
+ * @brief Destructor
+ * @return void
+ */
+ public function __destruct()
+ {
+ if ($this->image) {
+ if ($this->isImagick()) {
+ $this->image->clear();
+ $this->image->destroy();
+ return;
+ }
+ if (is_resource($this->image)) {
+ imagedestroy($this->image);
+ }
+ }
+ }
+
+ /**
+ * @return boolean
+ */
+ public function isImagick()
+ {
+ return $this->imagick;
+ }
+
+ /**
+ * @brief Maps Mime types to Imagick formats
+ * @return arr With with image formats (mime type as key)
+ */
+ public static function getFormatsMap()
+ {
+ $m = array(
+ 'image/jpeg' => 'JPG',
+ 'image/png' => 'PNG',
+ 'image/gif' => 'GIF'
+ );
+ return $m;
+ }
+
+ /**
+ * @param object $data data
+ * @return boolean
+ */
+ private function loadData($data)
+ {
+ if ($this->isImagick()) {
+ $this->image = new Imagick();
+ try {
+ $this->image->readImageBlob($data);
+ } catch (Exception $e) {
+ // Imagick couldn't use the data
+ return false;
+ }
+
+ /*
+ * Setup the image to the format it will be saved to
+ */
+ $map = self::getFormatsMap();
+ $format = $map[$type];
+ $this->image->setFormat($format);
+
+ // Always coalesce, if it is not a multi-frame image it won't hurt anyway
+ $this->image = $this->image->coalesceImages();
+
+ /*
+ * setup the compression here, so we'll do it only once
+ */
+ switch ($this->getType()) {
+ case "image/png":
+ $quality = Config::get('system', 'png_quality');
+ if ((! $quality) || ($quality > 9)) {
+ $quality = PNG_QUALITY;
+ }
+ /*
+ * From http://www.imagemagick.org/script/command-line-options.php#quality:
+ *
+ * 'For the MNG and PNG image formats, the quality value sets
+ * the zlib compression level (quality / 10) and filter-type (quality % 10).
+ * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
+ * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
+ */
+ $quality = $quality * 10;
+ $this->image->setCompressionQuality($quality);
+ break;
+ case "image/jpeg":
+ $quality = Config::get('system', 'jpeg_quality');
+ if ((! $quality) || ($quality > 100)) {
+ $quality = JPEG_QUALITY;
+ }
+ $this->image->setCompressionQuality($quality);
+ }
+
+ // The 'width' and 'height' properties are only used by non-Imagick routines.
+ $this->width = $this->image->getImageWidth();
+ $this->height = $this->image->getImageHeight();
+ $this->valid = true;
+
+ return true;
+ }
+
+ $this->valid = false;
+ $this->image = @imagecreatefromstring($data);
+ if ($this->image !== false) {
+ $this->width = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ $this->valid = true;
+ imagealphablending($this->image, false);
+ imagesavealpha($this->image, true);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @return boolean
+ */
+ public function isValid()
+ {
+ if ($this->isImagick()) {
+ return ($this->image !== false);
+ }
+ return $this->valid;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getWidth()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ return $this->image->getImageWidth();
+ }
+ return $this->width;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getHeight()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ return $this->image->getImageHeight();
+ }
+ return $this->height;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getImage()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ /* Clean it */
+ $this->image = $this->image->deconstructImages();
+ return $this->image;
+ }
+ return $this->image;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getType()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ return $this->type;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getExt()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ return $this->types[$this->getType()];
+ }
+
+ /**
+ * @param integer $max max dimension
+ * @return mixed
+ */
+ public function scaleDown($max)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ $width = $this->getWidth();
+ $height = $this->getHeight();
+
+ $dest_width = $dest_height = 0;
+
+ if ((! $width)|| (! $height)) {
+ return false;
+ }
+
+ if ($width > $max && $height > $max) {
+ // very tall image (greater than 16:9)
+ // constrain the width - let the height float.
+
+ if ((($height * 9) / 16) > $width) {
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } elseif ($width > $height) {
+ // else constrain both dimensions
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } else {
+ $dest_width = intval(($width * $max) / $height);
+ $dest_height = $max;
+ }
+ } else {
+ if ($width > $max) {
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } else {
+ if ($height > $max) {
+ // very tall image (greater than 16:9)
+ // but width is OK - don't do anything
+
+ if ((($height * 9) / 16) > $width) {
+ $dest_width = $width;
+ $dest_height = $height;
+ } else {
+ $dest_width = intval(($width * $max) / $height);
+ $dest_height = $max;
+ }
+ } else {
+ $dest_width = $width;
+ $dest_height = $height;
+ }
+ }
+ }
+
+
+ if ($this->isImagick()) {
+ /*
+ * If it is not animated, there will be only one iteration here,
+ * so don't bother checking
+ */
+ // Don't forget to go back to the first frame
+ $this->image->setFirstIterator();
+ do {
+ // FIXME - implement horizantal bias for scaling as in followin GD functions
+ // to allow very tall images to be constrained only horizontally.
+
+ $this->image->scaleDown($dest_width, $dest_height);
+ } while ($this->image->nextImage());
+
+ // These may not be necessary any more
+ $this->width = $this->image->getImageWidth();
+ $this->height = $this->image->getImageHeight();
+
+ return;
+ }
+
+
+ $dest = imagecreatetruecolor($dest_width, $dest_height);
+ imagealphablending($dest, false);
+ imagesavealpha($dest, true);
+ if ($this->type=='image/png') {
+ imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
+ }
+ imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
+ if ($this->image) {
+ imagedestroy($this->image);
+ }
+ $this->image = $dest;
+ $this->width = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ }
+
+ /**
+ * @param integer $degrees degrees to rotate image
+ * @return mixed
+ */
+ public function rotate($degrees)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ $this->image->setFirstIterator();
+ do {
+ $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
+ } while ($this->image->nextImage());
+ return;
+ }
+
+ // if script dies at this point check memory_limit setting in php.ini
+ $this->image = imagerotate($this->image, $degrees, 0);
+ $this->width = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ }
+
+ /**
+ * @param boolean $horiz optional, default true
+ * @param boolean $vert optional, default false
+ * @return mixed
+ */
+ public function flip($horiz = true, $vert = false)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ $this->image->setFirstIterator();
+ do {
+ if ($horiz) {
+ $this->image->flipImage();
+ }
+ if ($vert) {
+ $this->image->flopImage();
+ }
+ } while ($this->image->nextImage());
+ return;
+ }
+
+ $w = imagesx($this->image);
+ $h = imagesy($this->image);
+ $flipped = imagecreate($w, $h);
+ if ($horiz) {
+ for ($x = 0; $x < $w; $x++) {
+ imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
+ }
+ }
+ if ($vert) {
+ for ($y = 0; $y < $h; $y++) {
+ imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
+ }
+ }
+ $this->image = $flipped;
+ }
+
+ /**
+ * @param string $filename filename
+ * @return mixed
+ */
+ public function orient($filename)
+ {
+ if ($this->isImagick()) {
+ // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
+ $orientation = $this->image->getImageOrientation();
+ switch ($orientation) {
+ case Imagick::ORIENTATION_BOTTOMRIGHT:
+ $this->image->rotateimage("#000", 180);
+ break;
+ case Imagick::ORIENTATION_RIGHTTOP:
+ $this->image->rotateimage("#000", 90);
+ break;
+ case Imagick::ORIENTATION_LEFTBOTTOM:
+ $this->image->rotateimage("#000", -90);
+ break;
+ }
+
+ $this->image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
+ return true;
+ }
+ // based off comment on http://php.net/manual/en/function.imagerotate.php
+
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
+ return;
+ }
+
+ $exif = @exif_read_data($filename, null, true);
+ if (!$exif) {
+ return;
+ }
+
+ $ort = $exif['IFD0']['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;
+ }
+
+ // logger('exif: ' . print_r($exif,true));
+ return $exif;
+ }
+
+ /**
+ * @param integer $min minimum dimension
+ * @return mixed
+ */
+ public function scaleUp($min)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ $width = $this->getWidth();
+ $height = $this->getHeight();
+
+ $dest_width = $dest_height = 0;
+
+ if ((!$width)|| (!$height)) {
+ return false;
+ }
+
+ if ($width < $min && $height < $min) {
+ if ($width > $height) {
+ $dest_width = $min;
+ $dest_height = intval(($height * $min) / $width);
+ } else {
+ $dest_width = intval(($width * $min) / $height);
+ $dest_height = $min;
+ }
+ } else {
+ if ($width < $min) {
+ $dest_width = $min;
+ $dest_height = intval(($height * $min) / $width);
+ } else {
+ if ($height < $min) {
+ $dest_width = intval(($width * $min) / $height);
+ $dest_height = $min;
+ } else {
+ $dest_width = $width;
+ $dest_height = $height;
+ }
+ }
+ }
+
+ if ($this->isImagick()) {
+ return $this->scaleDown($dest_width, $dest_height);
+ }
+
+ $dest = imagecreatetruecolor($dest_width, $dest_height);
+ imagealphablending($dest, false);
+ imagesavealpha($dest, true);
+ if ($this->type=='image/png') {
+ imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
+ }
+ imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
+ if ($this->image) {
+ imagedestroy($this->image);
+ }
+ $this->image = $dest;
+ $this->width = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ }
+
+ /**
+ * @param integer $dim dimension
+ * @return mixed
+ */
+ public function scaleToSquare($dim)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ $this->image->setFirstIterator();
+ do {
+ $this->image->scaleDown($dim, $dim);
+ } while ($this->image->nextImage());
+ return;
+ }
+
+ $dest = imagecreatetruecolor($dim, $dim);
+ imagealphablending($dest, false);
+ imagesavealpha($dest, true);
+ if ($this->type=='image/png') {
+ imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
+ }
+ imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
+ if ($this->image) {
+ imagedestroy($this->image);
+ }
+ $this->image = $dest;
+ $this->width = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ }
+
+ /**
+ * @param integer $max maximum
+ * @param integer $x x coordinate
+ * @param integer $y y coordinate
+ * @param integer $w width
+ * @param integer $h height
+ * @return mixed
+ */
+ public function crop($max, $x, $y, $w, $h)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ $this->image->setFirstIterator();
+ do {
+ $this->image->cropImage($w, $h, $x, $y);
+ /*
+ * We need to remove the canva,
+ * or the image is not resized to the crop:
+ * http://php.net/manual/en/imagick.cropimage.php#97232
+ */
+ $this->image->setImagePage(0, 0, 0, 0);
+ } while ($this->image->nextImage());
+ return $this->scaleDown($max);
+ }
+
+ $dest = imagecreatetruecolor($max, $max);
+ imagealphablending($dest, false);
+ imagesavealpha($dest, true);
+ if ($this->type=='image/png') {
+ imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
+ }
+ imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
+ if ($this->image) {
+ imagedestroy($this->image);
+ }
+ $this->image = $dest;
+ $this->width = imagesx($this->image);
+ $this->height = imagesy($this->image);
+ }
+
+ /**
+ * @param string $path file path
+ * @return mixed
+ */
+ public function saveToFilePath($path)
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ $string = $this->asString();
+
+ $a = get_app();
+
+ $stamp1 = microtime(true);
+ file_put_contents($path, $string);
+ $a->save_timestamp($stamp1, "file");
+ }
+
+ /**
+ * @brief Magic method allowing string casting of an Image object
+ *
+ * Ex: $data = $Image->asString();
+ * can be replaced by
+ * $data = (string) $Image;
+ *
+ * @return string
+ */
+ public function __toString() {
+ return $this->asString();
+ }
+
+ /**
+ * @return mixed
+ */
+ public function asString()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
+
+ if ($this->isImagick()) {
+ /* Clean it */
+ $this->image = $this->image->deconstructImages();
+ $string = $this->image->getImagesBlob();
+ return $string;
+ }
+
+ $quality = false;
+
+ ob_start();
+
+ // Enable interlacing
+ imageinterlace($this->image, true);
+
+ switch ($this->getType()) {
+ case "image/png":
+ $quality = Config::get('system', 'png_quality');
+ if ((!$quality) || ($quality > 9)) {
+ $quality = PNG_QUALITY;
+ }
+ imagepng($this->image, null, $quality);
+ break;
+ case "image/jpeg":
+ $quality = Config::get('system', 'jpeg_quality');
+ if ((!$quality) || ($quality > 100)) {
+ $quality = JPEG_QUALITY;
+ }
+ imagejpeg($this->image, null, $quality);
+ }
+ $string = ob_get_contents();
+ ob_end_clean();
+
+ return $string;
+ }
+
+ /**
+ * Guess image mimetype from filename or from Content-Type header
+ *
+ * @param string $filename Image filename
+ * @param boolean $fromcurl Check Content-Type header from curl request
+ *
+ * @return object
+ */
+ public static function guessType($filename, $fromcurl = false)
+ {
+ logger('Image: guessType: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
+ $type = null;
+ if ($fromcurl) {
+ $a = get_app();
+ $headers=array();
+ $h = explode("\n", $a->get_curl_headers());
+ foreach ($h as $l) {
+ list($k,$v) = array_map("trim", explode(":", trim($l), 2));
+ $headers[$k] = $v;
+ }
+ if (array_key_exists('Content-Type', $headers))
+ $type = $headers['Content-Type'];
+ }
+ if (is_null($type)) {
+ // 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();
+ $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
+ } else {
+ $ext = pathinfo($filename, PATHINFO_EXTENSION);
+ $types = self::supportedTypes();
+ $type = "image/jpeg";
+ foreach ($types as $m => $e) {
+ if ($ext == $e) {
+ $type = $m;
+ }
+ }
+ }
+ }
+ logger('Image: guessType: type='.$type, LOGGER_DEBUG);
+ return $type;
+ }
+
+ /**
+ * @param string $url url
+ * @return object
+ */
+ public static function getInfoFromURL($url)
+ {
+ $data = array();
+
+ $data = Cache::get($url);
+
+ if (is_null($data) || !$data || !is_array($data)) {
+ $img_str = fetch_url($url, true, $redirects, 4);
+ $filesize = strlen($img_str);
+
+ if (function_exists("getimagesizefromstring")) {
+ $data = getimagesizefromstring($img_str);
+ } else {
+ $tempfile = tempnam(get_temppath(), "cache");
+
+ $a = get_app();
+ $stamp1 = microtime(true);
+ file_put_contents($tempfile, $img_str);
+ $a->save_timestamp($stamp1, "file");
+
+ $data = getimagesize($tempfile);
+ unlink($tempfile);
+ }
+
+ if ($data) {
+ $data["size"] = $filesize;
+ }
+
+ Cache::set($url, $data);
+ }
+
+ return $data;
+ }
+
+ /**
+ * @param integer $width width
+ * @param integer $height height
+ * @param integer $max max
+ * @return array
+ */
+ public static function getScalingDimensions($width, $height, $max)
+ {
+ $dest_width = $dest_height = 0;
+
+ if ((!$width) || (!$height)) {
+ return false;
+ }
+
+ if ($width > $max && $height > $max) {
+ // very tall image (greater than 16:9)
+ // constrain the width - let the height float.
+
+ if ((($height * 9) / 16) > $width) {
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } elseif ($width > $height) {
+ // else constrain both dimensions
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } else {
+ $dest_width = intval(($width * $max) / $height);
+ $dest_height = $max;
+ }
+ } else {
+ if ($width > $max) {
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } else {
+ if ($height > $max) {
+ // very tall image (greater than 16:9)
+ // but width is OK - don't do anything
+
+ if ((($height * 9) / 16) > $width) {
+ $dest_width = $width;
+ $dest_height = $height;
+ } else {
+ $dest_width = intval(($width * $max) / $height);
+ $dest_height = $max;
+ }
+ } else {
+ $dest_width = $width;
+ $dest_height = $height;
+ }
+ }
+ }
+ return array("width" => $dest_width, "height" => $dest_height);
+ }
+
+ /**
+ * @brief This function is used by the fromgplus addon
+ * @param object $a App
+ * @param integer $uid user id
+ * @param string $imagedata optional, default empty
+ * @param string $url optional, default empty
+ * @return array
+ */
+ public static function storePhoto(App $a, $uid, $imagedata = "", $url = "")
+ {
+ $r = q(
+ "SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
+ WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
+ intval($uid)
+ );
+
+ if (!DBM::is_result($r)) {
+ logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
+ return(array());
+ }
+
+ $page_owner_nick = $r[0]['nickname'];
+
+ /// @TODO
+ /// $default_cid = $r[0]['id'];
+ /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
+
+ if ((strlen($imagedata) == 0) && ($url == "")) {
+ logger("No image data and no url provided", LOGGER_DEBUG);
+ return(array());
+ } elseif (strlen($imagedata) == 0) {
+ logger("Uploading picture from ".$url, LOGGER_DEBUG);
+
+ $stamp1 = microtime(true);
+ $imagedata = @file_get_contents($url);
+ $a->save_timestamp($stamp1, "file");
+ }
+
+ $maximagesize = Config::get('system', 'maximagesize');
+
+ if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
+ logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
+ return(array());
+ }
+
+ $tempfile = tempnam(get_temppath(), "cache");
+
+ $stamp1 = microtime(true);
+ file_put_contents($tempfile, $imagedata);
+ $a->save_timestamp($stamp1, "file");
+
+ $data = getimagesize($tempfile);
+
+ if (!isset($data["mime"])) {
+ unlink($tempfile);
+ logger("File is no picture", LOGGER_DEBUG);
+ return(array());
+ }
+
+ $Image = new Image($imagedata, $data["mime"]);
+
+ if (!$Image->isValid()) {
+ unlink($tempfile);
+ logger("Picture is no valid picture", LOGGER_DEBUG);
+ return(array());
+ }
+
+ $Image->orient($tempfile);
+ unlink($tempfile);
+
+ $max_length = Config::get('system', 'max_image_length');
+ if (! $max_length) {
+ $max_length = MAX_IMAGE_LENGTH;
+ }
+
+ if ($max_length > 0) {
+ $Image->scaleDown($max_length);
+ }
+
+ $width = $Image->getWidth();
+ $height = $Image->getHeight();
+
+ $hash = photo_new_resource();
+
+ $smallest = 0;
+
+ // Pictures are always public by now
+ //$defperm = '<'.$default_cid.'>';
+ $defperm = "";
+ $visitor = 0;
+
+ $r = Photo::store($Image, $uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
+
+ if (!$r) {
+ logger("Picture couldn't be stored", LOGGER_DEBUG);
+ return(array());
+ }
+
+ $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
+ "full" => System::baseUrl()."/photo/{$hash}-0.".$Image->getExt());
+
+ if ($width > 800 || $height > 800) {
+ $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$Image->getExt();
+ }
+
+ if ($width > 640 || $height > 640) {
+ $Image->scaleDown(640);
+ $r = Photo::store($Image, $uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
+ if ($r) {
+ $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$Image->getExt();
+ }
+ }
+
+ if ($width > 320 || $height > 320) {
+ $Image->scaleDown(320);
+ $r = Photo::store($Image, $uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
+ if ($r) {
+ $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$Image->getExt();
+ }
+ }
+
+ if ($width > 160 && $height > 160) {
+ $x = 0;
+ $y = 0;
+
+ $min = $Image->getWidth();
+ if ($min > 160) {
+ $x = ($min - 160) / 2;
+ }
+
+ if ($Image->getHeight() < $min) {
+ $min = $Image->getHeight();
+ if ($min > 160) {
+ $y = ($min - 160) / 2;
+ }
+ }
+
+ $min = 160;
+ $Image->crop(160, $x, $y, $min, $min);
+
+ $r = Photo::store($Image, $uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
+ if ($r) {
+ $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$Image->getExt();
+ }
+ }
+
+ // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
+ $image["preview"] = $image["full"];
+
+ // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
+ //if (isset($image["thumb"]))
+ // $image["preview"] = $image["thumb"];
+
+ // Unsure, if this should be activated or deactivated
+ //if (isset($image["small"]))
+ // $image["preview"] = $image["small"];
+
+ if (isset($image["medium"])) {
+ $image["preview"] = $image["medium"];
+ }
+
+ return($image);
+ }
+}
+++ /dev/null
-<?php
-/**
- * @file src/Object/Photo.php
- * @brief This file contains the Photo class for image processing
- */
-namespace Friendica\Object;
-
-use Friendica\App;
-use Friendica\Core\Cache;
-use Friendica\Core\Config;
-use Friendica\Core\System;
-use Friendica\Database\DBM;
-use dba;
-use Exception;
-use Imagick;
-use ImagickPixel;
-
-require_once "include/photos.php";
-
-/**
- * Class to handle Photos
- */
-class Photo
-{
- private $image;
-
- /*
- * Put back gd stuff, not everybody have Imagick
- */
- private $imagick;
- private $width;
- private $height;
- private $valid;
- private $type;
- private $types;
-
- /**
- * @brief supported mimetypes and corresponding file extensions
- * @return array
- */
- public static function supportedTypes()
- {
- if (class_exists('Imagick')) {
- // Imagick::queryFormats won't help us a lot there...
- // At least, not yet, other parts of friendica uses this array
- $t = array(
- 'image/jpeg' => 'jpg',
- 'image/png' => 'png',
- 'image/gif' => 'gif'
- );
- } else {
- $t = array();
- $t['image/jpeg'] ='jpg';
- if (imagetypes() & IMG_PNG) {
- $t['image/png'] = 'png';
- }
- }
-
- return $t;
- }
-
- /**
- * @brief Constructor
- * @param object $data data
- * @param boolean $type optional, default null
- * @return object
- */
- public function __construct($data, $type = null)
- {
- $this->imagick = class_exists('Imagick');
- $this->types = static::supportedTypes();
- if (!array_key_exists($type, $this->types)) {
- $type='image/jpeg';
- }
- $this->type = $type;
-
- if ($this->isImagick() && $this->loadData($data)) {
- return true;
- } else {
- // Failed to load with Imagick, fallback
- $this->imagick = false;
- }
- return $this->loadData($data);
- }
-
- /**
- * @brief Destructor
- * @return void
- */
- public function __destruct()
- {
- if ($this->image) {
- if ($this->isImagick()) {
- $this->image->clear();
- $this->image->destroy();
- return;
- }
- if (is_resource($this->image)) {
- imagedestroy($this->image);
- }
- }
- }
-
- /**
- * @return boolean
- */
- public function isImagick()
- {
- return $this->imagick;
- }
-
- /**
- * @brief Maps Mime types to Imagick formats
- * @return arr With with image formats (mime type as key)
- */
- public static function getFormatsMap()
- {
- $m = array(
- 'image/jpeg' => 'JPG',
- 'image/png' => 'PNG',
- 'image/gif' => 'GIF'
- );
- return $m;
- }
-
- /**
- * @param object $data data
- * @return boolean
- */
- private function loadData($data)
- {
- if ($this->isImagick()) {
- $this->image = new Imagick();
- try {
- $this->image->readImageBlob($data);
- } catch (Exception $e) {
- // Imagick couldn't use the data
- return false;
- }
-
- /*
- * Setup the image to the format it will be saved to
- */
- $map = self::getFormatsMap();
- $format = $map[$type];
- $this->image->setFormat($format);
-
- // Always coalesce, if it is not a multi-frame image it won't hurt anyway
- $this->image = $this->image->coalesceImages();
-
- /*
- * setup the compression here, so we'll do it only once
- */
- switch ($this->getType()) {
- case "image/png":
- $quality = Config::get('system', 'png_quality');
- if ((! $quality) || ($quality > 9)) {
- $quality = PNG_QUALITY;
- }
- /*
- * From http://www.imagemagick.org/script/command-line-options.php#quality:
- *
- * 'For the MNG and PNG image formats, the quality value sets
- * the zlib compression level (quality / 10) and filter-type (quality % 10).
- * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
- * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
- */
- $quality = $quality * 10;
- $this->image->setCompressionQuality($quality);
- break;
- case "image/jpeg":
- $quality = Config::get('system', 'jpeg_quality');
- if ((! $quality) || ($quality > 100)) {
- $quality = JPEG_QUALITY;
- }
- $this->image->setCompressionQuality($quality);
- }
-
- // The 'width' and 'height' properties are only used by non-Imagick routines.
- $this->width = $this->image->getImageWidth();
- $this->height = $this->image->getImageHeight();
- $this->valid = true;
-
- return true;
- }
-
- $this->valid = false;
- $this->image = @imagecreatefromstring($data);
- if ($this->image !== false) {
- $this->width = imagesx($this->image);
- $this->height = imagesy($this->image);
- $this->valid = true;
- imagealphablending($this->image, false);
- imagesavealpha($this->image, true);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * @return boolean
- */
- public function isValid()
- {
- if ($this->isImagick()) {
- return ($this->image !== false);
- }
- return $this->valid;
- }
-
- /**
- * @return mixed
- */
- public function getWidth()
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- return $this->image->getImageWidth();
- }
- return $this->width;
- }
-
- /**
- * @return mixed
- */
- public function getHeight()
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- return $this->image->getImageHeight();
- }
- return $this->height;
- }
-
- /**
- * @return mixed
- */
- public function getImage()
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- /* Clean it */
- $this->image = $this->image->deconstructImages();
- return $this->image;
- }
- return $this->image;
- }
-
- /**
- * @return mixed
- */
- public function getType()
- {
- if (!$this->isValid()) {
- return false;
- }
-
- return $this->type;
- }
-
- /**
- * @return mixed
- */
- public function getExt()
- {
- if (!$this->isValid()) {
- return false;
- }
-
- return $this->types[$this->getType()];
- }
-
- /**
- * @param integer $max max dimension
- * @return mixed
- */
- public function scaleImage($max)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- $width = $this->getWidth();
- $height = $this->getHeight();
-
- $dest_width = $dest_height = 0;
-
- if ((! $width)|| (! $height)) {
- return false;
- }
-
- if ($width > $max && $height > $max) {
- // very tall image (greater than 16:9)
- // constrain the width - let the height float.
-
- if ((($height * 9) / 16) > $width) {
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } elseif ($width > $height) {
- // else constrain both dimensions
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } else {
- $dest_width = intval(($width * $max) / $height);
- $dest_height = $max;
- }
- } else {
- if ($width > $max) {
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } else {
- if ($height > $max) {
- // very tall image (greater than 16:9)
- // but width is OK - don't do anything
-
- if ((($height * 9) / 16) > $width) {
- $dest_width = $width;
- $dest_height = $height;
- } else {
- $dest_width = intval(($width * $max) / $height);
- $dest_height = $max;
- }
- } else {
- $dest_width = $width;
- $dest_height = $height;
- }
- }
- }
-
-
- if ($this->isImagick()) {
- /*
- * If it is not animated, there will be only one iteration here,
- * so don't bother checking
- */
- // Don't forget to go back to the first frame
- $this->image->setFirstIterator();
- do {
- // FIXME - implement horizantal bias for scaling as in followin GD functions
- // to allow very tall images to be constrained only horizontally.
-
- $this->image->scaleImage($dest_width, $dest_height);
- } while ($this->image->nextImage());
-
- // These may not be necessary any more
- $this->width = $this->image->getImageWidth();
- $this->height = $this->image->getImageHeight();
-
- return;
- }
-
-
- $dest = imagecreatetruecolor($dest_width, $dest_height);
- imagealphablending($dest, false);
- imagesavealpha($dest, true);
- if ($this->type=='image/png') {
- imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
- }
- imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
- if ($this->image) {
- imagedestroy($this->image);
- }
- $this->image = $dest;
- $this->width = imagesx($this->image);
- $this->height = imagesy($this->image);
- }
-
- /**
- * @param integer $degrees degrees to rotate image
- * @return mixed
- */
- public function rotate($degrees)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- $this->image->setFirstIterator();
- do {
- $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
- } while ($this->image->nextImage());
- return;
- }
-
- // if script dies at this point check memory_limit setting in php.ini
- $this->image = imagerotate($this->image, $degrees, 0);
- $this->width = imagesx($this->image);
- $this->height = imagesy($this->image);
- }
-
- /**
- * @param boolean $horiz optional, default true
- * @param boolean $vert optional, default false
- * @return mixed
- */
- public function flip($horiz = true, $vert = false)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- $this->image->setFirstIterator();
- do {
- if ($horiz) {
- $this->image->flipImage();
- }
- if ($vert) {
- $this->image->flopImage();
- }
- } while ($this->image->nextImage());
- return;
- }
-
- $w = imagesx($this->image);
- $h = imagesy($this->image);
- $flipped = imagecreate($w, $h);
- if ($horiz) {
- for ($x = 0; $x < $w; $x++) {
- imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
- }
- }
- if ($vert) {
- for ($y = 0; $y < $h; $y++) {
- imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
- }
- }
- $this->image = $flipped;
- }
-
- /**
- * @param string $filename filename
- * @return mixed
- */
- public function orient($filename)
- {
- if ($this->isImagick()) {
- // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
- $orientation = $this->image->getImageOrientation();
- switch ($orientation) {
- case Imagick::ORIENTATION_BOTTOMRIGHT:
- $this->image->rotateimage("#000", 180);
- break;
- case Imagick::ORIENTATION_RIGHTTOP:
- $this->image->rotateimage("#000", 90);
- break;
- case Imagick::ORIENTATION_LEFTBOTTOM:
- $this->image->rotateimage("#000", -90);
- break;
- }
-
- $this->image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
- return true;
- }
- // based off comment on http://php.net/manual/en/function.imagerotate.php
-
- if (!$this->isValid()) {
- return false;
- }
-
- if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
- return;
- }
-
- $exif = @exif_read_data($filename, null, true);
- if (!$exif) {
- return;
- }
-
- $ort = $exif['IFD0']['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;
- }
-
- // logger('exif: ' . print_r($exif,true));
- return $exif;
- }
-
- /**
- * @param integer $min minimum dimension
- * @return mixed
- */
- public function scaleImageUp($min)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- $width = $this->getWidth();
- $height = $this->getHeight();
-
- $dest_width = $dest_height = 0;
-
- if ((!$width)|| (!$height)) {
- return false;
- }
-
- if ($width < $min && $height < $min) {
- if ($width > $height) {
- $dest_width = $min;
- $dest_height = intval(($height * $min) / $width);
- } else {
- $dest_width = intval(($width * $min) / $height);
- $dest_height = $min;
- }
- } else {
- if ($width < $min) {
- $dest_width = $min;
- $dest_height = intval(($height * $min) / $width);
- } else {
- if ($height < $min) {
- $dest_width = intval(($width * $min) / $height);
- $dest_height = $min;
- } else {
- $dest_width = $width;
- $dest_height = $height;
- }
- }
- }
-
- if ($this->isImagick()) {
- return $this->scaleImage($dest_width, $dest_height);
- }
-
- $dest = imagecreatetruecolor($dest_width, $dest_height);
- imagealphablending($dest, false);
- imagesavealpha($dest, true);
- if ($this->type=='image/png') {
- imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
- }
- imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
- if ($this->image) {
- imagedestroy($this->image);
- }
- $this->image = $dest;
- $this->width = imagesx($this->image);
- $this->height = imagesy($this->image);
- }
-
- /**
- * @param integer $dim dimension
- * @return mixed
- */
- public function scaleImageSquare($dim)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- $this->image->setFirstIterator();
- do {
- $this->image->scaleImage($dim, $dim);
- } while ($this->image->nextImage());
- return;
- }
-
- $dest = imagecreatetruecolor($dim, $dim);
- imagealphablending($dest, false);
- imagesavealpha($dest, true);
- if ($this->type=='image/png') {
- imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
- }
- imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
- if ($this->image) {
- imagedestroy($this->image);
- }
- $this->image = $dest;
- $this->width = imagesx($this->image);
- $this->height = imagesy($this->image);
- }
-
- /**
- * @param integer $max maximum
- * @param integer $x x coordinate
- * @param integer $y y coordinate
- * @param integer $w width
- * @param integer $h height
- * @return mixed
- */
- public function cropImage($max, $x, $y, $w, $h)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- $this->image->setFirstIterator();
- do {
- $this->image->cropImage($w, $h, $x, $y);
- /*
- * We need to remove the canva,
- * or the image is not resized to the crop:
- * http://php.net/manual/en/imagick.cropimage.php#97232
- */
- $this->image->setImagePage(0, 0, 0, 0);
- } while ($this->image->nextImage());
- return $this->scaleImage($max);
- }
-
- $dest = imagecreatetruecolor($max, $max);
- imagealphablending($dest, false);
- imagesavealpha($dest, true);
- if ($this->type=='image/png') {
- imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
- }
- imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
- if ($this->image) {
- imagedestroy($this->image);
- }
- $this->image = $dest;
- $this->width = imagesx($this->image);
- $this->height = imagesy($this->image);
- }
-
- /**
- * @param string $path file path
- * @return mixed
- */
- public function saveImage($path)
- {
- if (!$this->isValid()) {
- return false;
- }
-
- $string = $this->imageString();
-
- $a = get_app();
-
- $stamp1 = microtime(true);
- file_put_contents($path, $string);
- $a->save_timestamp($stamp1, "file");
- }
-
- /**
- * @return mixed
- */
- public function imageString()
- {
- if (!$this->isValid()) {
- return false;
- }
-
- if ($this->isImagick()) {
- /* Clean it */
- $this->image = $this->image->deconstructImages();
- $string = $this->image->getImagesBlob();
- return $string;
- }
-
- $quality = false;
-
- ob_start();
-
- // Enable interlacing
- imageinterlace($this->image, true);
-
- switch ($this->getType()) {
- case "image/png":
- $quality = Config::get('system', 'png_quality');
- if ((!$quality) || ($quality > 9)) {
- $quality = PNG_QUALITY;
- }
- imagepng($this->image, null, $quality);
- break;
- case "image/jpeg":
- $quality = Config::get('system', 'jpeg_quality');
- if ((!$quality) || ($quality > 100)) {
- $quality = JPEG_QUALITY;
- }
- imagejpeg($this->image, null, $quality);
- }
- $string = ob_get_contents();
- ob_end_clean();
-
- return $string;
- }
-
- /**
- * @param integer $uid uid
- * @param integer $cid cid
- * @param integer $rid rid
- * @param string $filename filename
- * @param string $album album name
- * @param integer $scale scale
- * @param integer $profile optional, default = 0
- * @param string $allow_cid optional, default = ''
- * @param string $allow_gid optional, default = ''
- * @param string $deny_cid optional, default = ''
- * @param string $deny_gid optional, default = ''
- * @param string $desc optional, default = ''
- * @return object
- */
- public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
- {
- $r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
- if (DBM::is_result($r)) {
- $guid = $r['guid'];
- } else {
- $guid = get_guid();
- }
-
- $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1));
-
- $fields = array('uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, 'created' => datetime_convert(), 'edited' => datetime_convert(),
- 'filename' => basename($filename), 'type' => $this->getType(), 'album' => $album, 'height' => $this->getHeight(), 'width' => $this->getWidth(),
- 'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile,
- 'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc);
-
- if (DBM::is_result($x)) {
- $r = dba::update('photo', $fields, array('id' => $x['id']));
- } else {
- $r = dba::insert('photo', $fields);
- }
-
- return $r;
- }
-
- /**
- * Guess image mimetype from filename or from Content-Type header
- *
- * @param string $filename Image filename
- * @param boolean $fromcurl Check Content-Type header from curl request
- *
- * @return object
- */
- public static function guessImageType($filename, $fromcurl = false)
- {
- logger('Photo: guessImageType: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
- $type = null;
- if ($fromcurl) {
- $a = get_app();
- $headers=array();
- $h = explode("\n", $a->get_curl_headers());
- foreach ($h as $l) {
- list($k,$v) = array_map("trim", explode(":", trim($l), 2));
- $headers[$k] = $v;
- }
- if (array_key_exists('Content-Type', $headers))
- $type = $headers['Content-Type'];
- }
- if (is_null($type)) {
- // 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();
- $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
- } else {
- $ext = pathinfo($filename, PATHINFO_EXTENSION);
- $types = self::supportedTypes();
- $type = "image/jpeg";
- foreach ($types as $m => $e) {
- if ($ext == $e) {
- $type = $m;
- }
- }
- }
- }
- logger('Photo: guessImageType: type='.$type, LOGGER_DEBUG);
- return $type;
- }
-
- /**
- * @param string $photo photo
- * @param integer $uid user id
- * @param integer $cid contact id
- * @param boolean $quit_on_error optional, default false
- * @return array
- */
- public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
- {
- $r = dba::select(
- 'photo',
- array('resource-id'),
- array('uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos'),
- array('limit' => 1)
- );
-
- if (DBM::is_result($r) && strlen($r['resource-id'])) {
- $hash = $r['resource-id'];
- } else {
- $hash = photo_new_resource();
- }
-
- $photo_failure = false;
-
- $filename = basename($photo);
- $img_str = fetch_url($photo, true);
-
- if ($quit_on_error && ($img_str == "")) {
- return false;
- }
-
- $type = self::guessImageType($photo, true);
- $img = new Photo($img_str, $type);
- if ($img->isValid()) {
- $img->scaleImageSquare(175);
-
- $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
-
- if ($r === false) {
- $photo_failure = true;
- }
-
- $img->scaleImage(80);
-
- $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
-
- if ($r === false) {
- $photo_failure = true;
- }
-
- $img->scaleImage(48);
-
- $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
-
- if ($r === false) {
- $photo_failure = true;
- }
-
- $suffix = '?ts='.time();
-
- $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
- $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
- $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
-
- // Remove the cached photo
- $a = get_app();
- $basepath = $a->get_basepath();
-
- if (is_dir($basepath."/photo")) {
- $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
- if (file_exists($filename)) {
- unlink($filename);
- }
- $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
- if (file_exists($filename)) {
- unlink($filename);
- }
- $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
- if (file_exists($filename)) {
- unlink($filename);
- }
- }
- } else {
- $photo_failure = true;
- }
-
- if ($photo_failure && $quit_on_error) {
- return false;
- }
-
- if ($photo_failure) {
- $photo = System::baseUrl() . '/images/person-175.jpg';
- $thumb = System::baseUrl() . '/images/person-80.jpg';
- $micro = System::baseUrl() . '/images/person-48.jpg';
- }
-
- return array($photo, $thumb, $micro);
- }
-
- /**
- * @param string $url url
- * @return object
- */
- public static function getInfoFromURL($url)
- {
- $data = array();
-
- $data = Cache::get($url);
-
- if (is_null($data) || !$data || !is_array($data)) {
- $img_str = fetch_url($url, true, $redirects, 4);
- $filesize = strlen($img_str);
-
- if (function_exists("getimagesizefromstring")) {
- $data = getimagesizefromstring($img_str);
- } else {
- $tempfile = tempnam(get_temppath(), "cache");
-
- $a = get_app();
- $stamp1 = microtime(true);
- file_put_contents($tempfile, $img_str);
- $a->save_timestamp($stamp1, "file");
-
- $data = getimagesize($tempfile);
- unlink($tempfile);
- }
-
- if ($data) {
- $data["size"] = $filesize;
- }
-
- Cache::set($url, $data);
- }
-
- return $data;
- }
-
- /**
- * @param integer $width width
- * @param integer $height height
- * @param integer $max max
- * @return array
- */
- public static function scaleImageTo($width, $height, $max)
- {
- $dest_width = $dest_height = 0;
-
- if ((!$width) || (!$height)) {
- return false;
- }
-
- if ($width > $max && $height > $max) {
- // very tall image (greater than 16:9)
- // constrain the width - let the height float.
-
- if ((($height * 9) / 16) > $width) {
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } elseif ($width > $height) {
- // else constrain both dimensions
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } else {
- $dest_width = intval(($width * $max) / $height);
- $dest_height = $max;
- }
- } else {
- if ($width > $max) {
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } else {
- if ($height > $max) {
- // very tall image (greater than 16:9)
- // but width is OK - don't do anything
-
- if ((($height * 9) / 16) > $width) {
- $dest_width = $width;
- $dest_height = $height;
- } else {
- $dest_width = intval(($width * $max) / $height);
- $dest_height = $max;
- }
- } else {
- $dest_width = $width;
- $dest_height = $height;
- }
- }
- }
- return array("width" => $dest_width, "height" => $dest_height);
- }
-
- /**
- * @brief This function is used by the fromgplus addon
- * @param object $a App
- * @param integer $uid user id
- * @param string $imagedata optional, default empty
- * @param string $url optional, default empty
- * @return array
- */
- public static function storePhoto(App $a, $uid, $imagedata = "", $url = "")
- {
- $r = q(
- "SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
- WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
- intval($uid)
- );
-
- if (!DBM::is_result($r)) {
- logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
- return(array());
- }
-
- $page_owner_nick = $r[0]['nickname'];
-
- /// @TODO
- /// $default_cid = $r[0]['id'];
- /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
-
- if ((strlen($imagedata) == 0) && ($url == "")) {
- logger("No image data and no url provided", LOGGER_DEBUG);
- return(array());
- } elseif (strlen($imagedata) == 0) {
- logger("Uploading picture from ".$url, LOGGER_DEBUG);
-
- $stamp1 = microtime(true);
- $imagedata = @file_get_contents($url);
- $a->save_timestamp($stamp1, "file");
- }
-
- $maximagesize = Config::get('system', 'maximagesize');
-
- if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
- logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
- return(array());
- }
-
- $tempfile = tempnam(get_temppath(), "cache");
-
- $stamp1 = microtime(true);
- file_put_contents($tempfile, $imagedata);
- $a->save_timestamp($stamp1, "file");
-
- $data = getimagesize($tempfile);
-
- if (!isset($data["mime"])) {
- unlink($tempfile);
- logger("File is no picture", LOGGER_DEBUG);
- return(array());
- }
-
- $ph = new Photo($imagedata, $data["mime"]);
-
- if (!$ph->isValid()) {
- unlink($tempfile);
- logger("Picture is no valid picture", LOGGER_DEBUG);
- return(array());
- }
-
- $ph->orient($tempfile);
- unlink($tempfile);
-
- $max_length = Config::get('system', 'max_image_length');
- if (! $max_length) {
- $max_length = MAX_IMAGE_LENGTH;
- }
-
- if ($max_length > 0) {
- $ph->scaleImage($max_length);
- }
-
- $width = $ph->getWidth();
- $height = $ph->getHeight();
-
- $hash = photo_new_resource();
-
- $smallest = 0;
-
- // Pictures are always public by now
- //$defperm = '<'.$default_cid.'>';
- $defperm = "";
- $visitor = 0;
-
- $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
-
- if (!$r) {
- logger("Picture couldn't be stored", LOGGER_DEBUG);
- return(array());
- }
-
- $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
- "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
-
- if ($width > 800 || $height > 800) {
- $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt();
- }
-
- if ($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
- if ($r) {
- $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$ph->getExt();
- }
- }
-
- if ($width > 320 || $height > 320) {
- $ph->scaleImage(320);
- $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
- if ($r) {
- $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$ph->getExt();
- }
- }
-
- if ($width > 160 && $height > 160) {
- $x = 0;
- $y = 0;
-
- $min = $ph->getWidth();
- if ($min > 160) {
- $x = ($min - 160) / 2;
- }
-
- if ($ph->getHeight() < $min) {
- $min = $ph->getHeight();
- if ($min > 160) {
- $y = ($min - 160) / 2;
- }
- }
-
- $min = 160;
- $ph->cropImage(160, $x, $y, $min, $min);
-
- $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
- if ($r) {
- $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt();
- }
- }
-
- // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
- $image["preview"] = $image["full"];
-
- // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
- //if (isset($image["thumb"]))
- // $image["preview"] = $image["thumb"];
-
- // Unsure, if this should be activated or deactivated
- //if (isset($image["small"]))
- // $image["preview"] = $image["small"];
-
- if (isset($image["medium"])) {
- $image["preview"] = $image["medium"];
- }
-
- return($image);
- }
-}
namespace Friendica;
use Friendica\Core\Config;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
use Friendica\Util\XML;
use dba;
}
$src = self::completeUrl($attr["src"], $url);
- $photodata = Photo::getInfoFromURL($src);
+ $photodata = Image::getInfoFromURL($src);
if (($photodata) && ($photodata[0] > 150) && ($photodata[1] > 150)) {
if ($photodata[0] > 300) {
unset($siteinfo["image"]);
- $photodata = Photo::getInfoFromURL($src);
+ $photodata = Image::getInfoFromURL($src);
if (($photodata) && ($photodata[0] > 10) && ($photodata[1] > 10)) {
$siteinfo["images"][] = array("src" => $src,
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
+use Friendica\Model\Profile;
use Friendica\Object\Contact;
-use Friendica\Object\Photo;
-use Friendica\Object\Profile;
+use Friendica\Object\Image;
use Friendica\Protocol\OStatus;
use Friendica\Util\XML;
$uid
);
$photos = array();
- $ext = Photo::supportedTypes();
+ $ext = Image::supportedTypes();
foreach ($rp as $p) {
$photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
use Friendica\Object\Contact;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
use Friendica\Util\Lock;
use Friendica\Util\XML;
use dba;
switch ($siteinfo["type"]) {
case 'photo':
- $imgdata = Photo::getInfoFromURL($siteinfo["image"]);
+ $imgdata = Image::getInfoFromURL($siteinfo["image"]);
$attributes = array("rel" => "enclosure",
"href" => $siteinfo["image"],
"type" => $imgdata["mime"],
}
if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
- $imgdata = Photo::getInfoFromURL($siteinfo["image"]);
+ $imgdata = Image::getInfoFromURL($siteinfo["image"]);
$attributes = array("rel" => "enclosure",
"href" => $siteinfo["image"],
"type" => $imgdata["mime"],
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
-use Friendica\Object\Photo;
use Friendica\Object\Profile;
use dba;
use DOMDocument;
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Model\Photo;
+use Friendica\Object\Image;
/**
*
$r = q("SELECT * FROM `photo` WHERE `scale` = 4");
if (DBM::is_result($r)) {
foreach ($r as $rr) {
- $ph = new Photo($rr['data']);
- if ($ph->isValid()) {
- $ph->scaleImage(48);
- $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
+ $Image = new Image($rr['data']);
+ if ($Image->isValid()) {
+ $Image->scaleDown(48);
+ Photo::store($Image, $rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
}
}
}
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
$frio = "view/theme/frio";
*/
function frio_item_photo_links(App $a, &$body_info)
{
- $phototypes = Photo::supportedTypes();
+ $phototypes = Image::supportedTypes();
$occurence = 1;
$p = bb_find_open_close($body_info['html'], "<a", ">");
use Friendica\App;
use Friendica\Core\System;
-use Friendica\Object\Photo;
+use Friendica\Object\Image;
function frost_init(App $a) {
$a->videowidth = 400;
function frost_item_photo_links(App $a, &$body_info)
{
- $phototypes = Photo::supportedTypes();
+ $phototypes = Image::supportedTypes();
$occurence = 1;
$p = bb_find_open_close($body_info['html'], "<a", ">");