3 * @file include/Photo.php
4 * @brief This file contains the Photo class for image processing
8 use Friendica\Core\System;
10 require_once("include/photos.php");
17 * Put back gd stuff, not everybody have Imagick
27 * @brief supported mimetypes and corresponding file extensions
29 static function supportedTypes() {
30 if (class_exists('Imagick')) {
32 // Imagick::queryFormats won't help us a lot there...
33 // At least, not yet, other parts of friendica uses this array
35 'image/jpeg' => 'jpg',
41 $t['image/jpeg'] ='jpg';
42 if (imagetypes() & IMG_PNG) {
43 $t['image/png'] = 'png';
50 public function __construct($data, $type=null) {
51 $this->imagick = class_exists('Imagick');
52 $this->types = $this->supportedTypes();
53 if (!array_key_exists($type, $this->types)){
58 if ($this->is_imagick() && $this->load_data($data)) {
61 // Failed to load with Imagick, fallback
62 $this->imagick = false;
64 return $this->load_data($data);
67 public function __destruct() {
69 if ($this->is_imagick()) {
70 $this->image->clear();
71 $this->image->destroy();
74 if (is_resource($this->image)) {
75 imagedestroy($this->image);
80 public function is_imagick() {
81 return $this->imagick;
85 * @brief Maps Mime types to Imagick formats
86 * @return arr With with image formats (mime type as key)
88 public function get_FormatsMap() {
90 'image/jpeg' => 'JPG',
97 private function load_data($data) {
98 if ($this->is_imagick()) {
99 $this->image = new Imagick();
101 $this->image->readImageBlob($data);
102 } catch (Exception $e) {
103 // Imagick couldn't use the data
108 * Setup the image to the format it will be saved to
110 $map = $this->get_FormatsMap();
111 $format = $map[$type];
112 $this->image->setFormat($format);
114 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
115 $this->image = $this->image->coalesceImages();
118 * setup the compression here, so we'll do it only once
120 switch($this->getType()){
122 $quality = get_config('system', 'png_quality');
123 if ((! $quality) || ($quality > 9)) {
124 $quality = PNG_QUALITY;
127 * From http://www.imagemagick.org/script/command-line-options.php#quality:
129 * 'For the MNG and PNG image formats, the quality value sets
130 * the zlib compression level (quality / 10) and filter-type (quality % 10).
131 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
132 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
134 $quality = $quality * 10;
135 $this->image->setCompressionQuality($quality);
138 $quality = get_config('system', 'jpeg_quality');
139 if ((! $quality) || ($quality > 100)) {
140 $quality = JPEG_QUALITY;
142 $this->image->setCompressionQuality($quality);
145 // The 'width' and 'height' properties are only used by non-Imagick routines.
146 $this->width = $this->image->getImageWidth();
147 $this->height = $this->image->getImageHeight();
153 $this->valid = false;
154 $this->image = @imagecreatefromstring($data);
155 if ($this->image !== false) {
156 $this->width = imagesx($this->image);
157 $this->height = imagesy($this->image);
159 imagealphablending($this->image, false);
160 imagesavealpha($this->image, true);
168 public function is_valid() {
169 if ($this->is_imagick()) {
170 return ($this->image !== false);
175 public function getWidth() {
176 if (!$this->is_valid()) {
180 if ($this->is_imagick()) {
181 return $this->image->getImageWidth();
186 public function getHeight() {
187 if (!$this->is_valid()) {
191 if ($this->is_imagick()) {
192 return $this->image->getImageHeight();
194 return $this->height;
197 public function getImage() {
198 if (!$this->is_valid()) {
202 if ($this->is_imagick()) {
204 $this->image = $this->image->deconstructImages();
210 public function getType() {
211 if (!$this->is_valid()) {
218 public function getExt() {
219 if (!$this->is_valid()) {
223 return $this->types[$this->getType()];
226 public function scaleImage($max) {
227 if (!$this->is_valid()) {
231 $width = $this->getWidth();
232 $height = $this->getHeight();
234 $dest_width = $dest_height = 0;
236 if ((! $width)|| (! $height)) {
240 if ($width > $max && $height > $max) {
242 // very tall image (greater than 16:9)
243 // constrain the width - let the height float.
245 if ((($height * 9) / 16) > $width) {
247 $dest_height = intval(($height * $max) / $width);
248 } elseif ($width > $height) {
249 // else constrain both dimensions
251 $dest_height = intval(($height * $max) / $width);
253 $dest_width = intval(($width * $max) / $height);
259 $dest_height = intval(($height * $max) / $width);
261 if ($height > $max) {
263 // very tall image (greater than 16:9)
264 // but width is OK - don't do anything
266 if ((($height * 9) / 16) > $width) {
267 $dest_width = $width;
268 $dest_height = $height;
270 $dest_width = intval(($width * $max) / $height);
274 $dest_width = $width;
275 $dest_height = $height;
281 if ($this->is_imagick()) {
283 * If it is not animated, there will be only one iteration here,
284 * so don't bother checking
286 // Don't forget to go back to the first frame
287 $this->image->setFirstIterator();
290 // FIXME - implement horizantal bias for scaling as in followin GD functions
291 // to allow very tall images to be constrained only horizontally.
293 $this->image->scaleImage($dest_width, $dest_height);
294 } while ($this->image->nextImage());
296 // These may not be necessary any more
297 $this->width = $this->image->getImageWidth();
298 $this->height = $this->image->getImageHeight();
304 $dest = imagecreatetruecolor($dest_width, $dest_height);
305 imagealphablending($dest, false);
306 imagesavealpha($dest, true);
307 if ($this->type=='image/png') {
308 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
310 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
312 imagedestroy($this->image);
314 $this->image = $dest;
315 $this->width = imagesx($this->image);
316 $this->height = imagesy($this->image);
319 public function rotate($degrees) {
320 if (!$this->is_valid()) {
324 if ($this->is_imagick()) {
325 $this->image->setFirstIterator();
327 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
328 } while ($this->image->nextImage());
332 // if script dies at this point check memory_limit setting in php.ini
333 $this->image = imagerotate($this->image,$degrees,0);
334 $this->width = imagesx($this->image);
335 $this->height = imagesy($this->image);
338 public function flip($horiz = true, $vert = false) {
339 if (!$this->is_valid()) {
343 if ($this->is_imagick()) {
344 $this->image->setFirstIterator();
347 $this->image->flipImage();
350 $this->image->flopImage();
352 } while ($this->image->nextImage());
356 $w = imagesx($this->image);
357 $h = imagesy($this->image);
358 $flipped = imagecreate($w, $h);
360 for ($x = 0; $x < $w; $x++) {
361 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
365 for ($y = 0; $y < $h; $y++) {
366 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
369 $this->image = $flipped;
372 public function orient($filename) {
373 if ($this->is_imagick()) {
374 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
375 $orientation = $this->image->getImageOrientation();
376 switch ($orientation) {
377 case imagick::ORIENTATION_BOTTOMRIGHT:
378 $this->image->rotateimage("#000", 180);
380 case imagick::ORIENTATION_RIGHTTOP:
381 $this->image->rotateimage("#000", 90);
383 case imagick::ORIENTATION_LEFTBOTTOM:
384 $this->image->rotateimage("#000", -90);
388 $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
391 // based off comment on http://php.net/manual/en/function.imagerotate.php
393 if (!$this->is_valid()) {
397 if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
401 $exif = @exif_read_data($filename,null,true);
406 $ort = $exif['IFD0']['Orientation'];
413 case 2: // horizontal flip
417 case 3: // 180 rotate left
421 case 4: // vertical flip
422 $this->flip(false, true);
425 case 5: // vertical flip + 90 rotate right
426 $this->flip(false, true);
430 case 6: // 90 rotate right
434 case 7: // horizontal flip + 90 rotate right
439 case 8: // 90 rotate left
444 // logger('exif: ' . print_r($exif,true));
451 public function scaleImageUp($min) {
452 if (!$this->is_valid()) {
457 $width = $this->getWidth();
458 $height = $this->getHeight();
460 $dest_width = $dest_height = 0;
462 if ((!$width)|| (!$height)) {
466 if ($width < $min && $height < $min) {
467 if ($width > $height) {
469 $dest_height = intval(($height * $min) / $width);
471 $dest_width = intval(($width * $min) / $height);
477 $dest_height = intval(($height * $min) / $width);
479 if ($height < $min) {
480 $dest_width = intval(($width * $min) / $height);
483 $dest_width = $width;
484 $dest_height = $height;
489 if ($this->is_imagick()) {
490 return $this->scaleImage($dest_width, $dest_height);
493 $dest = imagecreatetruecolor($dest_width, $dest_height);
494 imagealphablending($dest, false);
495 imagesavealpha($dest, true);
496 if ($this->type=='image/png') {
497 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
499 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
501 imagedestroy($this->image);
503 $this->image = $dest;
504 $this->width = imagesx($this->image);
505 $this->height = imagesy($this->image);
510 public function scaleImageSquare($dim) {
511 if (!$this->is_valid()) {
515 if ($this->is_imagick()) {
516 $this->image->setFirstIterator();
518 $this->image->scaleImage($dim, $dim);
519 } while ($this->image->nextImage());
523 $dest = imagecreatetruecolor($dim, $dim);
524 imagealphablending($dest, false);
525 imagesavealpha($dest, true);
526 if ($this->type=='image/png') {
527 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
529 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
531 imagedestroy($this->image);
533 $this->image = $dest;
534 $this->width = imagesx($this->image);
535 $this->height = imagesy($this->image);
539 public function cropImage($max, $x, $y, $w, $h) {
540 if (!$this->is_valid()) {
544 if ($this->is_imagick()) {
545 $this->image->setFirstIterator();
547 $this->image->cropImage($w, $h, $x, $y);
549 * We need to remove the canva,
550 * or the image is not resized to the crop:
551 * http://php.net/manual/en/imagick.cropimage.php#97232
553 $this->image->setImagePage(0, 0, 0, 0);
554 } while ($this->image->nextImage());
555 return $this->scaleImage($max);
558 $dest = imagecreatetruecolor($max, $max);
559 imagealphablending($dest, false);
560 imagesavealpha($dest, true);
561 if ($this->type=='image/png') {
562 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
564 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
566 imagedestroy($this->image);
568 $this->image = $dest;
569 $this->width = imagesx($this->image);
570 $this->height = imagesy($this->image);
573 public function saveImage($path) {
574 if (!$this->is_valid()) {
578 $string = $this->imageString();
582 $stamp1 = microtime(true);
583 file_put_contents($path, $string);
584 $a->save_timestamp($stamp1, "file");
587 public function imageString() {
588 if (!$this->is_valid()) {
592 if ($this->is_imagick()) {
594 $this->image = $this->image->deconstructImages();
595 $string = $this->image->getImagesBlob();
603 // Enable interlacing
604 imageinterlace($this->image, true);
606 switch($this->getType()){
608 $quality = get_config('system', 'png_quality');
609 if ((!$quality) || ($quality > 9)) {
610 $quality = PNG_QUALITY;
612 imagepng($this->image, null, $quality);
615 $quality = get_config('system', 'jpeg_quality');
616 if ((!$quality) || ($quality > 100)) {
617 $quality = JPEG_QUALITY;
619 imagejpeg($this->image, null, $quality);
621 $string = ob_get_contents();
629 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') {
631 $r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1",
634 if (dbm::is_result($r)) {
635 $guid = $r[0]['guid'];
640 $x = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `contact-id` = %d AND `scale` = %d LIMIT 1",
646 if (dbm::is_result($x)) {
647 $r = q("UPDATE `photo`
651 `resource-id` = '%s',
674 dbesc(datetime_convert()),
675 dbesc(datetime_convert()),
676 dbesc(basename($filename)),
677 dbesc($this->getType()),
679 intval($this->getHeight()),
680 intval($this->getWidth()),
681 dbesc(strlen($this->imageString())),
682 dbesc($this->imageString()),
693 $r = q("INSERT INTO `photo`
694 (`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `desc`)
695 VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s')",
700 dbesc(datetime_convert()),
701 dbesc(datetime_convert()),
702 dbesc(basename($filename)),
703 dbesc($this->getType()),
705 intval($this->getHeight()),
706 intval($this->getWidth()),
707 dbesc(strlen($this->imageString())),
708 dbesc($this->imageString()),
725 * Guess image mimetype from filename or from Content-Type header
727 * @arg $filename string Image filename
728 * @arg $fromcurl boolean Check Content-Type header from curl request
730 function guess_image_type($filename, $fromcurl=false) {
731 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
736 $h = explode("\n",$a->get_curl_headers());
738 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
741 if (array_key_exists('Content-Type', $headers))
742 $type = $headers['Content-Type'];
745 // Guessing from extension? Isn't that... dangerous?
746 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
748 * Well, this not much better,
749 * but at least it comes from the data inside the image,
750 * we won't be tricked by a manipulated extension
752 $image = new Imagick($filename);
753 $type = $image->getImageMimeType();
754 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
756 $ext = pathinfo($filename, PATHINFO_EXTENSION);
757 $types = Photo::supportedTypes();
758 $type = "image/jpeg";
759 foreach ($types as $m => $e){
766 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
772 * @brief Updates the avatar links in a contact only if needed
774 * @param string $avatar Link to avatar picture
775 * @param int $uid User id of contact owner
776 * @param int $cid Contact id
777 * @param bool $force force picture update
779 * @return array Returns array of the different avatar sizes
781 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
782 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
783 if (!dbm::is_result($r)) {
786 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
789 if (($r[0]["avatar"] != $avatar) || $force) {
790 $photos = import_profile_photo($avatar, $uid, $cid, true);
793 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
794 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
795 dbesc(datetime_convert()), intval($cid));
797 // Update the public contact (contact id = 0)
799 $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
800 if (dbm::is_result($pcontact)) {
801 update_contact_avatar($avatar, 0, $pcontact['id'], $force);
812 function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
814 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
818 if (dbm::is_result($r) && strlen($r[0]['resource-id'])) {
819 $hash = $r[0]['resource-id'];
821 $hash = photo_new_resource();
824 $photo_failure = false;
826 $filename = basename($photo);
827 $img_str = fetch_url($photo, true);
829 if ($quit_on_error && ($img_str == "")) {
833 $type = guess_image_type($photo, true);
834 $img = new Photo($img_str, $type);
835 if ($img->is_valid()) {
837 $img->scaleImageSquare(175);
839 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
842 $photo_failure = true;
844 $img->scaleImage(80);
846 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
849 $photo_failure = true;
851 $img->scaleImage(48);
853 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
856 $photo_failure = true;
859 $suffix = '?ts='.time();
861 $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
862 $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
863 $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
865 // Remove the cached photo
867 $basepath = $a->get_basepath();
869 if (is_dir($basepath."/photo")) {
870 $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
871 if (file_exists($filename)) {
874 $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
875 if (file_exists($filename)) {
878 $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
879 if (file_exists($filename)) {
884 $photo_failure = true;
887 if ($photo_failure && $quit_on_error) {
891 if ($photo_failure) {
892 $photo = App::get_baseurl() . '/images/person-175.jpg';
893 $thumb = App::get_baseurl() . '/images/person-80.jpg';
894 $micro = App::get_baseurl() . '/images/person-48.jpg';
897 return(array($photo,$thumb,$micro));
901 function get_photo_info($url) {
904 $data = Cache::get($url);
906 if (is_null($data) || !$data || !is_array($data)) {
907 $img_str = fetch_url($url, true, $redirects, 4);
908 $filesize = strlen($img_str);
910 if (function_exists("getimagesizefromstring")) {
911 $data = getimagesizefromstring($img_str);
913 $tempfile = tempnam(get_temppath(), "cache");
916 $stamp1 = microtime(true);
917 file_put_contents($tempfile, $img_str);
918 $a->save_timestamp($stamp1, "file");
920 $data = getimagesize($tempfile);
925 $data["size"] = $filesize;
928 Cache::set($url, $data);
934 function scale_image($width, $height, $max) {
936 $dest_width = $dest_height = 0;
938 if ((!$width) || (!$height)) {
942 if ($width > $max && $height > $max) {
944 // very tall image (greater than 16:9)
945 // constrain the width - let the height float.
947 if ((($height * 9) / 16) > $width) {
949 $dest_height = intval(($height * $max) / $width);
950 } elseif ($width > $height) {
951 // else constrain both dimensions
953 $dest_height = intval(($height * $max) / $width);
955 $dest_width = intval(($width * $max) / $height);
961 $dest_height = intval(($height * $max) / $width);
963 if ($height > $max) {
965 // very tall image (greater than 16:9)
966 // but width is OK - don't do anything
968 if ((($height * 9) / 16) > $width) {
969 $dest_width = $width;
970 $dest_height = $height;
972 $dest_width = intval(($width * $max) / $height);
976 $dest_width = $width;
977 $dest_height = $height;
981 return array("width" => $dest_width, "height" => $dest_height);
984 function store_photo(App $a, $uid, $imagedata = "", $url = "") {
985 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
986 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
989 if (!dbm::is_result($r)) {
990 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
994 $page_owner_nick = $r[0]['nickname'];
997 /// $default_cid = $r[0]['id'];
998 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
1000 if ((strlen($imagedata) == 0) && ($url == "")) {
1001 logger("No image data and no url provided", LOGGER_DEBUG);
1003 } elseif (strlen($imagedata) == 0) {
1004 logger("Uploading picture from ".$url, LOGGER_DEBUG);
1006 $stamp1 = microtime(true);
1007 $imagedata = @file_get_contents($url);
1008 $a->save_timestamp($stamp1, "file");
1011 $maximagesize = get_config('system', 'maximagesize');
1013 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
1014 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
1019 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1023 $limit = service_class_fetch($uid,'photo_upload_limit');
1025 if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
1026 logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
1031 $tempfile = tempnam(get_temppath(), "cache");
1033 $stamp1 = microtime(true);
1034 file_put_contents($tempfile, $imagedata);
1035 $a->save_timestamp($stamp1, "file");
1037 $data = getimagesize($tempfile);
1039 if (!isset($data["mime"])) {
1041 logger("File is no picture", LOGGER_DEBUG);
1045 $ph = new Photo($imagedata, $data["mime"]);
1047 if (!$ph->is_valid()) {
1049 logger("Picture is no valid picture", LOGGER_DEBUG);
1053 $ph->orient($tempfile);
1056 $max_length = get_config('system', 'max_image_length');
1057 if (! $max_length) {
1058 $max_length = MAX_IMAGE_LENGTH;
1060 if ($max_length > 0) {
1061 $ph->scaleImage($max_length);
1064 $width = $ph->getWidth();
1065 $height = $ph->getHeight();
1067 $hash = photo_new_resource();
1071 // Pictures are always public by now
1072 //$defperm = '<'.$default_cid.'>';
1076 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1079 logger("Picture couldn't be stored", LOGGER_DEBUG);
1083 $image = array("page" => App::get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1084 "full" => App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt());
1086 if ($width > 800 || $height > 800) {
1087 $image["large"] = App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt();
1090 if ($width > 640 || $height > 640) {
1091 $ph->scaleImage(640);
1092 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1094 $image["medium"] = App::get_baseurl()."/photo/{$hash}-1.".$ph->getExt();
1098 if ($width > 320 || $height > 320) {
1099 $ph->scaleImage(320);
1100 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1102 $image["small"] = App::get_baseurl()."/photo/{$hash}-2.".$ph->getExt();
1106 if ($width > 160 && $height > 160) {
1110 $min = $ph->getWidth();
1112 $x = ($min - 160) / 2;
1115 if ($ph->getHeight() < $min) {
1116 $min = $ph->getHeight();
1118 $y = ($min - 160) / 2;
1123 $ph->cropImage(160, $x, $y, $min, $min);
1125 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1127 $image["thumb"] = App::get_baseurl()."/photo/{$hash}-3.".$ph->getExt();
1131 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1132 $image["preview"] = $image["full"];
1134 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1135 //if (isset($image["thumb"]))
1136 // $image["preview"] = $image["thumb"];
1138 // Unsure, if this should be activated or deactivated
1139 //if (isset($image["small"]))
1140 // $image["preview"] = $image["small"];
1142 if (isset($image["medium"])) {
1143 $image["preview"] = $image["medium"];