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 = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
632 if (dbm::is_result($r)) {
638 $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1));
640 $fields = array('uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, 'created' => datetime_convert(), 'edited' => datetime_convert(),
641 'filename' => basename($filename), 'type' => $this->getType(), 'album' => $album, 'height' => $this->getHeight(), 'width' => $this->getWidth(),
642 'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile,
643 'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc);
645 if (dbm::is_result($x)) {
646 $r = dba::update('photo', $fields, array('id' => $x['id']));
648 $r = dba::insert('photo', $fields);
657 * Guess image mimetype from filename or from Content-Type header
659 * @arg $filename string Image filename
660 * @arg $fromcurl boolean Check Content-Type header from curl request
662 function guess_image_type($filename, $fromcurl=false) {
663 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
668 $h = explode("\n",$a->get_curl_headers());
670 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
673 if (array_key_exists('Content-Type', $headers))
674 $type = $headers['Content-Type'];
677 // Guessing from extension? Isn't that... dangerous?
678 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
680 * Well, this not much better,
681 * but at least it comes from the data inside the image,
682 * we won't be tricked by a manipulated extension
684 $image = new Imagick($filename);
685 $type = $image->getImageMimeType();
686 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
688 $ext = pathinfo($filename, PATHINFO_EXTENSION);
689 $types = Photo::supportedTypes();
690 $type = "image/jpeg";
691 foreach ($types as $m => $e){
698 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
704 * @brief Updates the avatar links in a contact only if needed
706 * @param string $avatar Link to avatar picture
707 * @param int $uid User id of contact owner
708 * @param int $cid Contact id
709 * @param bool $force force picture update
711 * @return array Returns array of the different avatar sizes
713 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
714 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
715 if (!dbm::is_result($r)) {
718 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
721 if (($r[0]["avatar"] != $avatar) || $force) {
722 $photos = import_profile_photo($avatar, $uid, $cid, true);
725 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
726 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
727 dbesc(datetime_convert()), intval($cid));
729 // Update the public contact (contact id = 0)
731 $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
732 if (dbm::is_result($pcontact)) {
733 update_contact_avatar($avatar, 0, $pcontact['id'], $force);
744 function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
746 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
750 if (dbm::is_result($r) && strlen($r[0]['resource-id'])) {
751 $hash = $r[0]['resource-id'];
753 $hash = photo_new_resource();
756 $photo_failure = false;
758 $filename = basename($photo);
759 $img_str = fetch_url($photo, true);
761 if ($quit_on_error && ($img_str == "")) {
765 $type = guess_image_type($photo, true);
766 $img = new Photo($img_str, $type);
767 if ($img->is_valid()) {
769 $img->scaleImageSquare(175);
771 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
774 $photo_failure = true;
776 $img->scaleImage(80);
778 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
781 $photo_failure = true;
783 $img->scaleImage(48);
785 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
788 $photo_failure = true;
791 $suffix = '?ts='.time();
793 $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
794 $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
795 $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
797 // Remove the cached photo
799 $basepath = $a->get_basepath();
801 if (is_dir($basepath."/photo")) {
802 $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
803 if (file_exists($filename)) {
806 $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
807 if (file_exists($filename)) {
810 $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
811 if (file_exists($filename)) {
816 $photo_failure = true;
819 if ($photo_failure && $quit_on_error) {
823 if ($photo_failure) {
824 $photo = System::baseUrl() . '/images/person-175.jpg';
825 $thumb = System::baseUrl() . '/images/person-80.jpg';
826 $micro = System::baseUrl() . '/images/person-48.jpg';
829 return(array($photo,$thumb,$micro));
833 function get_photo_info($url) {
836 $data = Cache::get($url);
838 if (is_null($data) || !$data || !is_array($data)) {
839 $img_str = fetch_url($url, true, $redirects, 4);
840 $filesize = strlen($img_str);
842 if (function_exists("getimagesizefromstring")) {
843 $data = getimagesizefromstring($img_str);
845 $tempfile = tempnam(get_temppath(), "cache");
848 $stamp1 = microtime(true);
849 file_put_contents($tempfile, $img_str);
850 $a->save_timestamp($stamp1, "file");
852 $data = getimagesize($tempfile);
857 $data["size"] = $filesize;
860 Cache::set($url, $data);
866 function scale_image($width, $height, $max) {
868 $dest_width = $dest_height = 0;
870 if ((!$width) || (!$height)) {
874 if ($width > $max && $height > $max) {
876 // very tall image (greater than 16:9)
877 // constrain the width - let the height float.
879 if ((($height * 9) / 16) > $width) {
881 $dest_height = intval(($height * $max) / $width);
882 } elseif ($width > $height) {
883 // else constrain both dimensions
885 $dest_height = intval(($height * $max) / $width);
887 $dest_width = intval(($width * $max) / $height);
893 $dest_height = intval(($height * $max) / $width);
895 if ($height > $max) {
897 // very tall image (greater than 16:9)
898 // but width is OK - don't do anything
900 if ((($height * 9) / 16) > $width) {
901 $dest_width = $width;
902 $dest_height = $height;
904 $dest_width = intval(($width * $max) / $height);
908 $dest_width = $width;
909 $dest_height = $height;
913 return array("width" => $dest_width, "height" => $dest_height);
916 function store_photo(App $a, $uid, $imagedata = "", $url = "") {
917 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
918 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
921 if (!dbm::is_result($r)) {
922 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
926 $page_owner_nick = $r[0]['nickname'];
929 /// $default_cid = $r[0]['id'];
930 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
932 if ((strlen($imagedata) == 0) && ($url == "")) {
933 logger("No image data and no url provided", LOGGER_DEBUG);
935 } elseif (strlen($imagedata) == 0) {
936 logger("Uploading picture from ".$url, LOGGER_DEBUG);
938 $stamp1 = microtime(true);
939 $imagedata = @file_get_contents($url);
940 $a->save_timestamp($stamp1, "file");
943 $maximagesize = get_config('system', 'maximagesize');
945 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
946 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
951 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
955 $limit = service_class_fetch($uid,'photo_upload_limit');
957 if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
958 logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
963 $tempfile = tempnam(get_temppath(), "cache");
965 $stamp1 = microtime(true);
966 file_put_contents($tempfile, $imagedata);
967 $a->save_timestamp($stamp1, "file");
969 $data = getimagesize($tempfile);
971 if (!isset($data["mime"])) {
973 logger("File is no picture", LOGGER_DEBUG);
977 $ph = new Photo($imagedata, $data["mime"]);
979 if (!$ph->is_valid()) {
981 logger("Picture is no valid picture", LOGGER_DEBUG);
985 $ph->orient($tempfile);
988 $max_length = get_config('system', 'max_image_length');
990 $max_length = MAX_IMAGE_LENGTH;
992 if ($max_length > 0) {
993 $ph->scaleImage($max_length);
996 $width = $ph->getWidth();
997 $height = $ph->getHeight();
999 $hash = photo_new_resource();
1003 // Pictures are always public by now
1004 //$defperm = '<'.$default_cid.'>';
1008 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1011 logger("Picture couldn't be stored", LOGGER_DEBUG);
1015 $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1016 "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
1018 if ($width > 800 || $height > 800) {
1019 $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt();
1022 if ($width > 640 || $height > 640) {
1023 $ph->scaleImage(640);
1024 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1026 $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$ph->getExt();
1030 if ($width > 320 || $height > 320) {
1031 $ph->scaleImage(320);
1032 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1034 $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$ph->getExt();
1038 if ($width > 160 && $height > 160) {
1042 $min = $ph->getWidth();
1044 $x = ($min - 160) / 2;
1047 if ($ph->getHeight() < $min) {
1048 $min = $ph->getHeight();
1050 $y = ($min - 160) / 2;
1055 $ph->cropImage(160, $x, $y, $min, $min);
1057 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1059 $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt();
1063 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1064 $image["preview"] = $image["full"];
1066 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1067 //if (isset($image["thumb"]))
1068 // $image["preview"] = $image["thumb"];
1070 // Unsure, if this should be activated or deactivated
1071 //if (isset($image["small"]))
1072 // $image["preview"] = $image["small"];
1074 if (isset($image["medium"])) {
1075 $image["preview"] = $image["medium"];