use Friendica\Core\System;
use Friendica\Database\DBM;
use dba;
+use Exception;
+use Imagick;
+use ImagickPixel;
require_once "include/photos.php";
/**
* @brief supported mimetypes and corresponding file extensions
+ * @return array
*/
public static function supportedTypes()
{
* @brief Maps Mime types to Imagick formats
* @return arr With with image formats (mime type as key)
*/
- public function getFormatsMap()
+ public static function getFormatsMap()
{
$m = array(
'image/jpeg' => 'JPG',
/*
* Setup the image to the format it will be saved to
*/
- $map = $this->getFormatsMap();
+ $map = self::getFormatsMap();
$format = $map[$type];
$this->image->setFormat($format);
// based off comment on http://php.net/manual/en/imagick.getimageorientation.php
$orientation = $this->image->getImageOrientation();
switch ($orientation) {
- case imagick::ORIENTATION_BOTTOMRIGHT:
+ case Imagick::ORIENTATION_BOTTOMRIGHT:
$this->image->rotateimage("#000", 180);
break;
- case imagick::ORIENTATION_RIGHTTOP:
+ case Imagick::ORIENTATION_RIGHTTOP:
$this->image->rotateimage("#000", 90);
break;
- case imagick::ORIENTATION_LEFTBOTTOM:
+ case Imagick::ORIENTATION_LEFTBOTTOM:
$this->image->rotateimage("#000", -90);
break;
}
- $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
+ $this->image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
return true;
}
// based off comment on http://php.net/manual/en/function.imagerotate.php
*
* @return object
*/
- public function guessImageType($filename, $fromcurl = false)
+ public static function guessImageType($filename, $fromcurl = false)
{
logger('Photo: guessImageType: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
$type = null;
$image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
} else {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
- $types = $this->supportedTypes();
+ $types = self::supportedTypes();
$type = "image/jpeg";
foreach ($types as $m => $e) {
if ($ext == $e) {
return $type;
}
- /**
- * @brief Updates the avatar links in a contact only if needed
- *
- * @param string $avatar Link to avatar picture
- * @param int $uid User id of contact owner
- * @param int $cid Contact id
- * @param bool $force force picture update
- *
- * @return array Returns array of the different avatar sizes
- */
- public function updateContactAvatar($avatar, $uid, $cid, $force = false)
- {
- // Limit = 1 returns the row so no need for dba:inArray()
- $r = dba::select('contact', array('avatar', 'photo', 'thumb', 'micro', 'nurl'), array('id' => $cid), array('limit' => 1));
- if (!DBM::is_result($r)) {
- return false;
- } else {
- $data = array($r["photo"], $r["thumb"], $r["micro"]);
- }
-
- if (($r["avatar"] != $avatar) || $force) {
- $photos = $this->importProfilePhoto($avatar, $uid, $cid, true);
-
- if ($photos) {
- dba::update(
- 'contact',
- array('avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => datetime_convert()),
- array('id' => $cid)
- );
-
- // Update the public contact (contact id = 0)
- if ($uid != 0) {
- $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
- if (DBM::is_result($pcontact)) {
- $this->updateContactAvatar($avatar, 0, $pcontact['id'], $force);
- }
- }
-
- return $photos;
- }
- }
-
- return $data;
- }
-
/**
* @param string $photo photo
* @param integer $uid user id
* @param boolean $quit_on_error optional, default false
* @return array
*/
- private function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
+ public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
{
$r = dba::select(
'photo',
return false;
}
- $type = $this->guessImageType($photo, true);
+ $type = self::guessImageType($photo, true);
$img = new Photo($img_str, $type);
if ($img->isValid()) {
$img->scaleImageSquare(175);
$micro = System::baseUrl() . '/images/person-48.jpg';
}
- return(array($photo, $thumb, $micro));
+ return array($photo, $thumb, $micro);
}
/**
* @param string $url url
* @return object
*/
- public function getPhotoInfo($url)
+ public static function getInfoFromURL($url)
{
$data = array();
* @param integer $max max
* @return array
*/
- public function scaleImageTo($width, $height, $max)
+ public static function scaleImageTo($width, $height, $max)
{
$dest_width = $dest_height = 0;
}
/**
- * @brief This function doesn't seem to be used
+ * @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
*/
- private function storePhoto(App $a, $uid, $imagedata = "", $url = "")
+ 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`
if (! $max_length) {
$max_length = MAX_IMAGE_LENGTH;
}
+
if ($max_length > 0) {
$ph->scaleImage($max_length);
}
}
$image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
- "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
+ "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
if ($width > 800 || $height > 800) {
$image["large"] = System::baseUrl()."/photo/{$hash}-0.".$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) {
$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();
// 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"];
+ // $image["preview"] = $image["thumb"];
// Unsure, if this should be activated or deactivated
//if (isset($image["small"]))
- // $image["preview"] = $image["small"];
+ // $image["preview"] = $image["small"];
if (isset($image["medium"])) {
$image["preview"] = $image["medium"];