Ejemplo n.º 1
0
     } else {
         $smarty->assign('imagetaken', '--');
     }
     $smarty->assign('today_imagetaken', date("Y-m-d"));
 } elseif ($step == 4) {
     $USER->getStats();
     $preview_url = "/submit.php?preview=" . $uploadmanager->upload_id;
     $smarty->assign('preview_url', $preview_url);
     $smarty->assign('preview_width', $uploadmanager->upload_width);
     $smarty->assign('preview_height', $uploadmanager->upload_height);
     $sizes = array();
     $widths = array();
     $heights = array();
     $showorig = false;
     if ($uploadmanager->initOriginalUploadSize() && $uploadmanager->hasoriginal) {
         list($destwidth, $destheight, $maxdim, $changedim) = $uploadmanager->_new_size($uploadmanager->original_width, $uploadmanager->original_height);
         $smarty->assign('original_width', $uploadmanager->original_width);
         $smarty->assign('original_height', $uploadmanager->original_height);
         if ($changedim) {
             $showorig = $CONF['img_size_unlimited'];
             foreach ($CONF['img_sizes'] as $cursize) {
                 list($destwidth, $destheight, $destdim, $changedim) = $uploadmanager->_new_size($uploadmanager->original_width, $uploadmanager->original_height, $cursize);
                 if (!$changedim && $showorig) {
                     break;
                 }
                 $sizes[] = $cursize;
                 $widths[] = $destwidth;
                 $heights[] = $destheight;
                 $maxdim = $destdim;
                 if (!$changedim) {
                     break;
Ejemplo n.º 2
0
 /**
  * general purpose internal method for creating resized images - accepts
  * a variety of options. Use this to build specific methods for public
  * consumption
  * 
  * maxw : maximum width of image (default '100')
  * maxh : maximum height of image (default '100')
  * bestfit : show entire image inside max width/height. If false
  *           then the image is cropped to match the aspect ratio of
  *           of the target area first (default 'true')
  * attribname : attribute name of img tag which holds url (default 'src')
  * bevel : give image a raised edge (default true)
  * unsharp : do an unsharp mask on the image
  * pano : do not crop, even if w:h > 2:1 (default false)
  * 
  * returns an association array containing 'html' element, which contains
  * a fragment to load the image, and 'path' containg relative url to image
  */
 function _getResized($params)
 {
     global $memcache, $CONF, $MESSAGES;
     $mkey = "{$this->gridimage_id}:" . md5(serialize($params));
     //fails quickly if not using memcached!
     $result =& $memcache->name_get('ir', $mkey);
     if ($result && $result['url'] != '/photos/error.jpg') {
         return $result;
     }
     //unpack known params and set defaults
     $maxw = isset($params['maxw']) ? $params['maxw'] : 100;
     $maxh = isset($params['maxh']) ? $params['maxh'] : 100;
     $attribname = isset($params['attribname']) ? $params['attribname'] : 'src';
     $bestfit = isset($params['bestfit']) ? $params['bestfit'] : true;
     $bevel = isset($params['bevel']) ? $params['bevel'] : true;
     $unsharp = isset($params['unsharp']) ? $params['unsharp'] : true;
     $pano = isset($params['pano']) ? $params['pano'] : false;
     $source = isset($params['source']) ? $params['source'] : '';
     global $CONF;
     //establish whether we have a cached thumbnail
     $ab = sprintf("%02d", floor($this->gridimage_id % 1000000 / 10000));
     $cd = sprintf("%02d", floor($this->gridimage_id % 10000 / 100));
     $abcdef = sprintf("%06d", $this->gridimage_id);
     $hash = $this->_getAntiLeechHash();
     $base = $_SERVER['DOCUMENT_ROOT'] . '/photos';
     if ($this->gridimage_id < 1000000) {
         $thumbpath = "/photos/{$ab}/{$cd}/{$abcdef}_{$hash}_{$maxw}x{$maxh}.jpg";
     } else {
         $yz = sprintf("%02d", floor($this->gridimage_id / 1000000));
         $thumbpath = "/geophotos/{$yz}/{$ab}/{$cd}/{$abcdef}_{$hash}_{$maxw}x{$maxh}.jpg";
     }
     if (!empty($params['urlonly']) && $params['urlonly'] !== 2 && file_exists($_SERVER['DOCUMENT_ROOT'] . $thumbpath)) {
         $return = array();
         $return['url'] = $thumbpath;
         if (!empty($CONF['enable_cluster'])) {
             $return['server'] = str_replace('0', $this->gridimage_id % $CONF['enable_cluster'], "http://{$CONF['STATIC_HOST']}");
         } else {
             $return['server'] = "http://" . $CONF['CONTENT_HOST'];
         }
         return $return;
     }
     $mkey = "{$this->gridimage_id}:{$maxw}x{$maxh}";
     //fails quickly if not using memcached!
     $size =& $memcache->name_get('is', $mkey);
     if ($size) {
         $return = array();
         $return['url'] = $thumbpath;
         $by = $MESSAGES['class_gridimage']['by'];
         $title = $this->grid_reference . ' : ' . htmlentities2($this->title) . $by . htmlentities2($this->realname);
         if (!empty($CONF['enable_cluster'])) {
             $return['server'] = str_replace('0', $this->gridimage_id % $CONF['enable_cluster'], "http://{$CONF['STATIC_HOST']}");
         } else {
             $return['server'] = "http://" . $CONF['CONTENT_HOST'];
         }
         $thumbpath = $return['server'] . $thumbpath;
         if (isset($CONF['curtail_level']) && $CONF['curtail_level'] > 1 && empty($GLOBALS['USER']->user_id) && isset($GLOBALS['smarty'])) {
             $thumbpath = cachize_url($thumbpath);
         }
         $html = "<img alt=\"{$title}\" {$attribname}=\"{$thumbpath}\" {$size[3]} />";
         $return['html'] = $html;
         return $return;
     }
     if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $thumbpath)) {
         if ($source == 'original') {
             $fullpath = $this->_getOriginalpath();
         } else {
             //get path to fullsize image (will try to fetch it from fetch_on_demand)
             $fullpath = $this->_getFullpath();
         }
         if ($pano && $fullpath != '/photos/error.jpg' && file_exists($_SERVER['DOCUMENT_ROOT'] . $fullpath)) {
             require_once "geograph/uploadmanager.class.php";
             $uploadmanager = new UploadManager();
             list($owidth, $oheight, $otype, $oattr) = getimagesize($_SERVER['DOCUMENT_ROOT'] . $fullpath);
             list($destwidth, $destheight, $destdim, $changedim) = $uploadmanager->_new_size($owidth, $oheight, $maxw);
             $maxw = $destdim;
             $maxh = $destdim;
             $bestfit = true;
         }
         if ($fullpath != '/photos/error.jpg' && file_exists($_SERVER['DOCUMENT_ROOT'] . $fullpath)) {
             if (strlen($CONF['imagemagick_path'])) {
                 if (($info = getimagesize($_SERVER['DOCUMENT_ROOT'] . $fullpath)) === FALSE) {
                     //couldn't read image!
                     $thumbpath = "/photos/error.jpg";
                 } else {
                     list($width, $height, $type, $attr) = $info;
                     if ($width > $maxw || $height > $maxh || !$bestfit) {
                         $unsharpen = $unsharp ? "-unsharp 0x1+0.8+0.1" : "";
                         $raised = $bevel ? "-raise 2x2" : "";
                         $operation = $maxw + $maxh < 400 ? 'thumbnail' : 'resize';
                         $aspect_src = $width / $height;
                         $aspect_dest = $maxw / $maxh;
                         if (!$pano && $bestfit && $aspect_src > 2 && $aspect_dest < 2) {
                             $bestfit = false;
                             $maxh = round($maxw / 2);
                             $aspect_dest = 2;
                         }
                         if ($bestfit) {
                             $cmd = sprintf("\"%sconvert\" -{$operation} %ldx%ld  {$unsharpen} {$raised} -quality 87 jpg:%s jpg:%s", $CONF['imagemagick_path'], $maxw, $maxh, $_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath);
                             passthru($cmd);
                         } else {
                             if ($aspect_src > $aspect_dest) {
                                 //src image is relatively wider - we'll trim the sides
                                 $optimum_width = round($height * $aspect_dest);
                                 $offset = round(($width - $optimum_width) / 2);
                                 $crop = "-crop {$optimum_width}x{$height}+{$offset}+0";
                             } else {
                                 //src image is relatively taller - we'll trim the top/bottom
                                 $optimum_height = round($width / $aspect_dest);
                                 $offset = round(($height - $optimum_height) / 2);
                                 $crop = "-crop {$width}x{$optimum_height}+0+{$offset}";
                             }
                             $cmd = sprintf("\"%sconvert\" {$crop} -quality 87 jpg:%s jpg:%s", $CONF['imagemagick_path'], $_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath);
                             passthru($cmd);
                             //now resize // FIXME: one step!
                             $cmd = sprintf("\"%smogrify\" -{$operation} %ldx%ld {$unsharpen} {$raised} -quality 87 jpg:%s", $CONF['imagemagick_path'], $maxw, $maxh, $_SERVER['DOCUMENT_ROOT'] . $thumbpath);
                             passthru($cmd);
                         }
                     } else {
                         //requested thumb is larger than original - stick with original
                         copy($_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath);
                     }
                 }
             } else {
                 // FIXME not the same as above
                 //generate resized image
                 $fullimg = @imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] . $fullpath);
                 if ($fullimg) {
                     $srcw = imagesx($fullimg);
                     $srch = imagesy($fullimg);
                     if ($srcw > $maxw || $srch > $maxh) {
                         //figure out size of image we'll keep
                         if ($srcw > $srch) {
                             //landscape
                             $destw = $maxw;
                             $desth = round($destw * $srch / $srcw);
                         } else {
                             //portrait
                             $desth = $maxh;
                             $destw = round($desth * $srcw / $srch);
                         }
                         $resized = imagecreatetruecolor($destw, $desth);
                         imagecopyresampled($resized, $fullimg, 0, 0, 0, 0, $destw, $desth, $srcw, $srch);
                         if ($unsharp) {
                             require_once 'geograph/image.inc.php';
                             UnsharpMask($resized, 100, 0.5, 3);
                         }
                         imagedestroy($fullimg);
                         //save the thumbnail
                         imagejpeg($resized, $_SERVER['DOCUMENT_ROOT'] . $thumbpath, 85);
                         imagedestroy($resized);
                     } elseif ($srcw == 0 && $srch == 0) {
                         //couldn't read image!
                         $thumbpath = "/photos/error.jpg";
                         imagedestroy($fullimg);
                     } else {
                         //requested thumb is larger than original - stick with original
                         copy($_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath);
                     }
                 } else {
                     //couldn't load full jpeg
                     $thumbpath = "/photos/error.jpg";
                 }
             }
         } else {
             //no original image! - return link to error image
             $thumbpath = "/photos/error.jpg";
         }
     }
     $return = array();
     $return['url'] = $thumbpath;
     if ($thumbpath == '/photos/error.jpg') {
         $html = "<img {$attribname}=\"{$thumbpath}\" width=\"{$maxw}\" height=\"{$maxh}\" />";
     } else {
         $by = $MESSAGES['class_gridimage']['by'];
         $title = $this->grid_reference . ' : ' . htmlentities2($this->title) . $by . htmlentities2($this->realname);
         $size = getimagesize($_SERVER['DOCUMENT_ROOT'] . $thumbpath);
         if (!empty($CONF['enable_cluster'])) {
             $return['server'] = str_replace('0', $this->gridimage_id % $CONF['enable_cluster'], "http://{$CONF['STATIC_HOST']}");
         } else {
             $return['server'] = "http://" . $CONF['CONTENT_HOST'];
         }
         $thumbpath = $return['server'] . $thumbpath;
         if (isset($CONF['curtail_level']) && $CONF['curtail_level'] > 1 && empty($GLOBALS['USER']->user_id) && isset($GLOBALS['smarty'])) {
             $thumbpath = cachize_url($thumbpath);
         }
         $html = "<img alt=\"{$title}\" {$attribname}=\"{$thumbpath}\" {$size[3]} />";
         //fails quickly if not using memcached!
         $memcache->name_set('is', $mkey, $size, $memcache->compress, $memcache->period_med);
     }
     $return['html'] = $html;
     return $return;
 }