3 * @file include/Photo.php
4 * @brief This file contains the Photo class for image processing
7 require_once("include/photos.php");
14 * Put back gd stuff, not everybody have Imagick
24 * @brief supported mimetypes and corresponding file extensions
26 static function supportedTypes() {
27 if (class_exists('Imagick')) {
29 // Imagick::queryFormats won't help us a lot there...
30 // At least, not yet, other parts of friendica uses this array
32 'image/jpeg' => 'jpg',
38 $t['image/jpeg'] ='jpg';
39 if (imagetypes() & IMG_PNG) {
40 $t['image/png'] = 'png';
47 public function __construct($data, $type=null) {
48 $this->imagick = class_exists('Imagick');
49 $this->types = $this->supportedTypes();
50 if (!array_key_exists($type, $this->types)){
55 if ($this->is_imagick() && $this->load_data($data)) {
58 // Failed to load with Imagick, fallback
59 $this->imagick = false;
61 return $this->load_data($data);
64 public function __destruct() {
66 if ($this->is_imagick()) {
67 $this->image->clear();
68 $this->image->destroy();
71 imagedestroy($this->image);
75 public function is_imagick() {
76 return $this->imagick;
80 * @brief Maps Mime types to Imagick formats
81 * @return arr With with image formats (mime type as key)
83 public function get_FormatsMap() {
85 'image/jpeg' => 'JPG',
92 private function load_data($data) {
93 if ($this->is_imagick()) {
94 $this->image = new Imagick();
96 $this->image->readImageBlob($data);
97 } catch (Exception $e) {
98 // Imagick couldn't use the data
103 * Setup the image to the format it will be saved to
105 $map = $this->get_FormatsMap();
106 $format = $map[$type];
107 $this->image->setFormat($format);
109 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
110 $this->image = $this->image->coalesceImages();
113 * setup the compression here, so we'll do it only once
115 switch($this->getType()){
117 $quality = get_config('system', 'png_quality');
118 if ((! $quality) || ($quality > 9)) {
119 $quality = PNG_QUALITY;
122 * From http://www.imagemagick.org/script/command-line-options.php#quality:
124 * 'For the MNG and PNG image formats, the quality value sets
125 * the zlib compression level (quality / 10) and filter-type (quality % 10).
126 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
127 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
129 $quality = $quality * 10;
130 $this->image->setCompressionQuality($quality);
133 $quality = get_config('system', 'jpeg_quality');
134 if ((! $quality) || ($quality > 100)) {
135 $quality = JPEG_QUALITY;
137 $this->image->setCompressionQuality($quality);
140 // The 'width' and 'height' properties are only used by non-Imagick routines.
141 $this->width = $this->image->getImageWidth();
142 $this->height = $this->image->getImageHeight();
148 $this->valid = false;
149 $this->image = @imagecreatefromstring($data);
150 if ($this->image !== false) {
151 $this->width = imagesx($this->image);
152 $this->height = imagesy($this->image);
154 imagealphablending($this->image, false);
155 imagesavealpha($this->image, true);
163 public function is_valid() {
164 if ($this->is_imagick()) {
165 return ($this->image !== false);
170 public function getWidth() {
171 if (!$this->is_valid()) {
175 if ($this->is_imagick()) {
176 return $this->image->getImageWidth();
181 public function getHeight() {
182 if (!$this->is_valid()) {
186 if ($this->is_imagick()) {
187 return $this->image->getImageHeight();
189 return $this->height;
192 public function getImage() {
193 if (!$this->is_valid()) {
197 if ($this->is_imagick()) {
199 $this->image = $this->image->deconstructImages();
205 public function getType() {
206 if (!$this->is_valid()) {
213 public function getExt() {
214 if (!$this->is_valid()) {
218 return $this->types[$this->getType()];
221 public function scaleImage($max) {
222 if (!$this->is_valid()) {
226 $width = $this->getWidth();
227 $height = $this->getHeight();
229 $dest_width = $dest_height = 0;
231 if ((! $width)|| (! $height)) {
235 if ($width > $max && $height > $max) {
237 // very tall image (greater than 16:9)
238 // constrain the width - let the height float.
240 if ((($height * 9) / 16) > $width) {
242 $dest_height = intval(($height * $max) / $width);
243 } elseif ($width > $height) {
244 // else constrain both dimensions
246 $dest_height = intval(($height * $max) / $width);
248 $dest_width = intval(($width * $max) / $height);
254 $dest_height = intval(($height * $max) / $width);
256 if ($height > $max) {
258 // very tall image (greater than 16:9)
259 // but width is OK - don't do anything
261 if ((($height * 9) / 16) > $width) {
262 $dest_width = $width;
263 $dest_height = $height;
265 $dest_width = intval(($width * $max) / $height);
269 $dest_width = $width;
270 $dest_height = $height;
276 if ($this->is_imagick()) {
278 * If it is not animated, there will be only one iteration here,
279 * so don't bother checking
281 // Don't forget to go back to the first frame
282 $this->image->setFirstIterator();
285 // FIXME - implement horizantal bias for scaling as in followin GD functions
286 // to allow very tall images to be constrained only horizontally.
288 $this->image->scaleImage($dest_width, $dest_height);
289 } while ($this->image->nextImage());
291 // These may not be necessary any more
292 $this->width = $this->image->getImageWidth();
293 $this->height = $this->image->getImageHeight();
299 $dest = imagecreatetruecolor($dest_width, $dest_height);
300 imagealphablending($dest, false);
301 imagesavealpha($dest, true);
302 if ($this->type=='image/png') {
303 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
305 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
307 imagedestroy($this->image);
309 $this->image = $dest;
310 $this->width = imagesx($this->image);
311 $this->height = imagesy($this->image);
314 public function rotate($degrees) {
315 if (!$this->is_valid()) {
319 if ($this->is_imagick()) {
320 $this->image->setFirstIterator();
322 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
323 } while ($this->image->nextImage());
327 $this->image = imagerotate($this->image,$degrees,0);
328 $this->width = imagesx($this->image);
329 $this->height = imagesy($this->image);
332 public function flip($horiz = true, $vert = false) {
333 if (!$this->is_valid()) {
337 if ($this->is_imagick()) {
338 $this->image->setFirstIterator();
341 $this->image->flipImage();
344 $this->image->flopImage();
346 } while ($this->image->nextImage());
350 $w = imagesx($this->image);
351 $h = imagesy($this->image);
352 $flipped = imagecreate($w, $h);
354 for ($x = 0; $x < $w; $x++) {
355 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
359 for ($y = 0; $y < $h; $y++) {
360 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
363 $this->image = $flipped;
366 public function orient($filename) {
367 if ($this->is_imagick()) {
368 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
369 $orientation = $this->image->getImageOrientation();
370 switch ($orientation) {
371 case imagick::ORIENTATION_BOTTOMRIGHT:
372 $this->image->rotateimage("#000", 180);
374 case imagick::ORIENTATION_RIGHTTOP:
375 $this->image->rotateimage("#000", 90);
377 case imagick::ORIENTATION_LEFTBOTTOM:
378 $this->image->rotateimage("#000", -90);
382 $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
385 // based off comment on http://php.net/manual/en/function.imagerotate.php
387 if (!$this->is_valid()) {
391 if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
395 $exif = @exif_read_data($filename,null,true);
400 $ort = $exif['IFD0']['Orientation'];
407 case 2: // horizontal flip
411 case 3: // 180 rotate left
415 case 4: // vertical flip
416 $this->flip(false, true);
419 case 5: // vertical flip + 90 rotate right
420 $this->flip(false, true);
424 case 6: // 90 rotate right
428 case 7: // horizontal flip + 90 rotate right
433 case 8: // 90 rotate left
438 // logger('exif: ' . print_r($exif,true));
445 public function scaleImageUp($min) {
446 if (!$this->is_valid()) {
451 $width = $this->getWidth();
452 $height = $this->getHeight();
454 $dest_width = $dest_height = 0;
456 if ((!$width)|| (!$height)) {
460 if ($width < $min && $height < $min) {
461 if ($width > $height) {
463 $dest_height = intval(($height * $min) / $width);
465 $dest_width = intval(($width * $min) / $height);
471 $dest_height = intval(($height * $min) / $width);
473 if ($height < $min) {
474 $dest_width = intval(($width * $min) / $height);
477 $dest_width = $width;
478 $dest_height = $height;
483 if ($this->is_imagick()) {
484 return $this->scaleImage($dest_width, $dest_height);
487 $dest = imagecreatetruecolor($dest_width, $dest_height);
488 imagealphablending($dest, false);
489 imagesavealpha($dest, true);
490 if ($this->type=='image/png') {
491 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
493 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
495 imagedestroy($this->image);
497 $this->image = $dest;
498 $this->width = imagesx($this->image);
499 $this->height = imagesy($this->image);
504 public function scaleImageSquare($dim) {
505 if (!$this->is_valid()) {
509 if ($this->is_imagick()) {
510 $this->image->setFirstIterator();
512 $this->image->scaleImage($dim, $dim);
513 } while ($this->image->nextImage());
517 $dest = imagecreatetruecolor($dim, $dim);
518 imagealphablending($dest, false);
519 imagesavealpha($dest, true);
520 if ($this->type=='image/png') {
521 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
523 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
525 imagedestroy($this->image);
527 $this->image = $dest;
528 $this->width = imagesx($this->image);
529 $this->height = imagesy($this->image);
533 public function cropImage($max, $x, $y, $w, $h) {
534 if (!$this->is_valid()) {
538 if ($this->is_imagick()) {
539 $this->image->setFirstIterator();
541 $this->image->cropImage($w, $h, $x, $y);
543 * We need to remove the canva,
544 * or the image is not resized to the crop:
545 * http://php.net/manual/en/imagick.cropimage.php#97232
547 $this->image->setImagePage(0, 0, 0, 0);
548 } while ($this->image->nextImage());
549 return $this->scaleImage($max);
552 $dest = imagecreatetruecolor($max, $max);
553 imagealphablending($dest, false);
554 imagesavealpha($dest, true);
555 if ($this->type=='image/png') {
556 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
558 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
560 imagedestroy($this->image);
562 $this->image = $dest;
563 $this->width = imagesx($this->image);
564 $this->height = imagesy($this->image);
567 public function saveImage($path) {
568 if (!$this->is_valid()) {
572 $string = $this->imageString();
576 $stamp1 = microtime(true);
577 file_put_contents($path, $string);
578 $a->save_timestamp($stamp1, "file");
581 public function imageString() {
582 if (!$this->is_valid()) {
586 if ($this->is_imagick()) {
588 $this->image = $this->image->deconstructImages();
589 $string = $this->image->getImagesBlob();
597 // Enable interlacing
598 imageinterlace($this->image, true);
600 switch($this->getType()){
602 $quality = get_config('system', 'png_quality');
603 if ((!$quality) || ($quality > 9)) {
604 $quality = PNG_QUALITY;
606 imagepng($this->image, null, $quality);
609 $quality = get_config('system', 'jpeg_quality');
610 if ((!$quality) || ($quality > 100)) {
611 $quality = JPEG_QUALITY;
613 imagejpeg($this->image, null, $quality);
615 $string = ob_get_contents();
623 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
625 $r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1",
628 if (dbm::is_result($r)) {
629 $guid = $r[0]['guid'];
634 $x = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `contact-id` = %d AND `scale` = %d LIMIT 1",
640 if (dbm::is_result($x)) {
641 $r = q("UPDATE `photo`
645 `resource-id` = '%s',
667 dbesc(datetime_convert()),
668 dbesc(datetime_convert()),
669 dbesc(basename($filename)),
670 dbesc($this->getType()),
672 intval($this->getHeight()),
673 intval($this->getWidth()),
674 dbesc(strlen($this->imageString())),
675 dbesc($this->imageString()),
685 $r = q("INSERT INTO `photo`
686 (`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`)
687 VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s')",
692 dbesc(datetime_convert()),
693 dbesc(datetime_convert()),
694 dbesc(basename($filename)),
695 dbesc($this->getType()),
697 intval($this->getHeight()),
698 intval($this->getWidth()),
699 dbesc(strlen($this->imageString())),
700 dbesc($this->imageString()),
716 * Guess image mimetype from filename or from Content-Type header
718 * @arg $filename string Image filename
719 * @arg $fromcurl boolean Check Content-Type header from curl request
721 function guess_image_type($filename, $fromcurl=false) {
722 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
727 $h = explode("\n",$a->get_curl_headers());
729 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
732 if (array_key_exists('Content-Type', $headers))
733 $type = $headers['Content-Type'];
736 // Guessing from extension? Isn't that... dangerous?
737 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
739 * Well, this not much better,
740 * but at least it comes from the data inside the image,
741 * we won't be tricked by a manipulated extension
743 $image = new Imagick($filename);
744 $type = $image->getImageMimeType();
745 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
747 $ext = pathinfo($filename, PATHINFO_EXTENSION);
748 $types = Photo::supportedTypes();
749 $type = "image/jpeg";
750 foreach ($types as $m => $e){
757 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
763 * @brief Updates the avatar links in a contact only if needed
765 * @param string $avatar Link to avatar picture
766 * @param int $uid User id of contact owner
767 * @param int $cid Contact id
768 * @param bool $force force picture update
770 * @return array Returns array of the different avatar sizes
772 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
774 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
775 if (!dbm::is_result($r)) {
778 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
781 if (($r[0]["avatar"] != $avatar) OR $force) {
782 $photos = import_profile_photo($avatar, $uid, $cid, true);
785 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
786 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
787 dbesc(datetime_convert()), intval($cid));
795 function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
797 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
801 if (dbm::is_result($r) && strlen($r[0]['resource-id'])) {
802 $hash = $r[0]['resource-id'];
804 $hash = photo_new_resource();
807 $photo_failure = false;
809 $filename = basename($photo);
810 $img_str = fetch_url($photo, true);
812 if ($quit_on_error AND ($img_str == "")) {
816 $type = guess_image_type($photo, true);
817 $img = new Photo($img_str, $type);
818 if ($img->is_valid()) {
820 $img->scaleImageSquare(175);
822 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
825 $photo_failure = true;
827 $img->scaleImage(80);
829 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
832 $photo_failure = true;
834 $img->scaleImage(48);
836 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
839 $photo_failure = true;
842 $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
843 $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
844 $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
846 $photo_failure = true;
849 if ($photo_failure AND $quit_on_error) {
853 if ($photo_failure) {
854 $photo = App::get_baseurl() . '/images/person-175.jpg';
855 $thumb = App::get_baseurl() . '/images/person-80.jpg';
856 $micro = App::get_baseurl() . '/images/person-48.jpg';
859 return(array($photo,$thumb,$micro));
863 function get_photo_info($url) {
866 $data = Cache::get($url);
868 if (is_null($data) OR !$data OR !is_array($data)) {
869 $img_str = fetch_url($url, true, $redirects, 4);
870 $filesize = strlen($img_str);
872 if (function_exists("getimagesizefromstring")) {
873 $data = getimagesizefromstring($img_str);
875 $tempfile = tempnam(get_temppath(), "cache");
878 $stamp1 = microtime(true);
879 file_put_contents($tempfile, $img_str);
880 $a->save_timestamp($stamp1, "file");
882 $data = getimagesize($tempfile);
887 $data["size"] = $filesize;
890 Cache::set($url, $data);
896 function scale_image($width, $height, $max) {
898 $dest_width = $dest_height = 0;
900 if ((!$width) || (!$height)) {
904 if ($width > $max && $height > $max) {
906 // very tall image (greater than 16:9)
907 // constrain the width - let the height float.
909 if ((($height * 9) / 16) > $width) {
911 $dest_height = intval(($height * $max) / $width);
912 } elseif ($width > $height) {
913 // else constrain both dimensions
915 $dest_height = intval(($height * $max) / $width);
917 $dest_width = intval(($width * $max) / $height);
923 $dest_height = intval(($height * $max) / $width);
925 if ($height > $max) {
927 // very tall image (greater than 16:9)
928 // but width is OK - don't do anything
930 if ((($height * 9) / 16) > $width) {
931 $dest_width = $width;
932 $dest_height = $height;
934 $dest_width = intval(($width * $max) / $height);
938 $dest_width = $width;
939 $dest_height = $height;
943 return array("width" => $dest_width, "height" => $dest_height);
946 function store_photo(App $a, $uid, $imagedata = "", $url = "") {
947 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
948 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
951 if (!dbm::is_result($r)) {
952 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
956 $page_owner_nick = $r[0]['nickname'];
959 /// $default_cid = $r[0]['id'];
960 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
962 if ((strlen($imagedata) == 0) AND ($url == "")) {
963 logger("No image data and no url provided", LOGGER_DEBUG);
965 } elseif (strlen($imagedata) == 0) {
966 logger("Uploading picture from ".$url, LOGGER_DEBUG);
968 $stamp1 = microtime(true);
969 $imagedata = @file_get_contents($url);
970 $a->save_timestamp($stamp1, "file");
973 $maximagesize = get_config('system', 'maximagesize');
975 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
976 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
981 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
985 $limit = service_class_fetch($uid,'photo_upload_limit');
987 if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
988 logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
993 $tempfile = tempnam(get_temppath(), "cache");
995 $stamp1 = microtime(true);
996 file_put_contents($tempfile, $imagedata);
997 $a->save_timestamp($stamp1, "file");
999 $data = getimagesize($tempfile);
1001 if (!isset($data["mime"])) {
1003 logger("File is no picture", LOGGER_DEBUG);
1007 $ph = new Photo($imagedata, $data["mime"]);
1009 if (!$ph->is_valid()) {
1011 logger("Picture is no valid picture", LOGGER_DEBUG);
1015 $ph->orient($tempfile);
1018 $max_length = get_config('system', 'max_image_length');
1019 if (! $max_length) {
1020 $max_length = MAX_IMAGE_LENGTH;
1022 if ($max_length > 0) {
1023 $ph->scaleImage($max_length);
1026 $width = $ph->getWidth();
1027 $height = $ph->getHeight();
1029 $hash = photo_new_resource();
1033 // Pictures are always public by now
1034 //$defperm = '<'.$default_cid.'>';
1038 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1041 logger("Picture couldn't be stored", LOGGER_DEBUG);
1045 $image = array("page" => App::get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1046 "full" => App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt());
1048 if ($width > 800 || $height > 800) {
1049 $image["large"] = App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt();
1052 if ($width > 640 || $height > 640) {
1053 $ph->scaleImage(640);
1054 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1056 $image["medium"] = App::get_baseurl()."/photo/{$hash}-1.".$ph->getExt();
1060 if ($width > 320 || $height > 320) {
1061 $ph->scaleImage(320);
1062 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1064 $image["small"] = App::get_baseurl()."/photo/{$hash}-2.".$ph->getExt();
1068 if ($width > 160 AND $height > 160) {
1072 $min = $ph->getWidth();
1074 $x = ($min - 160) / 2;
1077 if ($ph->getHeight() < $min) {
1078 $min = $ph->getHeight();
1080 $y = ($min - 160) / 2;
1085 $ph->cropImage(160, $x, $y, $min, $min);
1087 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1089 $image["thumb"] = App::get_baseurl()."/photo/{$hash}-3.".$ph->getExt();
1093 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1094 $image["preview"] = $image["full"];
1096 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1097 //if (isset($image["thumb"]))
1098 // $image["preview"] = $image["thumb"];
1100 // Unsure, if this should be activated or deactivated
1101 //if (isset($image["small"]))
1102 // $image["preview"] = $image["small"];
1104 if (isset($image["medium"])) {
1105 $image["preview"] = $image["medium"];