Ejemplo n.º 1
0
 /**
  * resize uploaded image and/or create thumbnails in same dir
  *
  * @param  int      $item_id    item id
  * @param  array    $opt        assocarray for resizing original and/or creating previews
  *                                ''  => array(w,h) or just 1 (defaults for original used)
  *                                's' => array(w,h) or just 1 (defaults for s used)
  *                                'm' => array(w,h) or just 1 (defaults for l used)
  *                                'l' => array(w,h) or just 1 (defaults for l used)
  * @return none
  */
 public static function upload_resize($filepath, $opt = array())
 {
     $pp = pathinfo($filepath);
     $dir = $pp['dirname'];
     $ext = '.' . $pp['extension'];
     $item_id = $pp['filename'];
     //file name without ext
     if (!self::is_img_ext($ext)) {
         return;
     }
     foreach ($opt as $size => $wh) {
         if (!is_array($wh)) {
             $wh = ImageUtils::$MAX_RESIZE_WH[$size];
         }
         #use defaults
         if (!is_array($wh)) {
             continue;
         }
         #if no resize width/heigh for the $size - skip resize for this $size
         $_size = $size > '' ? '_' . $size : '';
         $filepath_to = $dir . '/' . $item_id . $_size . $ext;
         #logger("image_resize: $filepath => $filepath_to, $wh[0], $wh[1]");
         ImageUtils::image_resize($filepath, $wh[0], $wh[1], $filepath_to);
     }
 }