Exemple #1
0
 /**
  * flagAdmin::resize_image() - create a new image, based on the height /width
  * 
  * @class flagAdmin
  * @param object | int $image contain all information about the image or the id
  * @param integer $width optional 
  * @param integer $height optional
  * @return string result code
  */
 static function resize_image($image, $width = 0, $height = 0)
 {
     global $flag;
     if (!class_exists('flag_Thumbnail')) {
         require_once flagGallery::graphic_library();
     }
     if (is_numeric($image)) {
         $image = flagdb::find_image($image);
     }
     if (!is_object($image)) {
         return __('Object didn\'t contain correct data', 'flag');
     }
     // before we start we import the meta data to database (required for uploads before V0.40)
     flagAdmin::maybe_import_meta($image->pid);
     // if no parameter is set, take global settings
     $width = $width == 0 ? $flag->options['imgWidth'] : $width;
     $height = $height == 0 ? $flag->options['imgHeight'] : $height;
     if (!is_writable($image->imagePath)) {
         return ' <strong>' . $image->filename . __(' is not writeable', 'flag') . '</strong>';
     }
     $file = new flag_Thumbnail($image->imagePath, TRUE);
     // skip if file is not there
     if (!$file->error) {
         $file->resize($width, $height, 4);
         $file->save($image->imagePath, $flag->options['imgQuality']);
         // read the new sizes
         $size = @getimagesize($image->imagePath);
         // add them to the database
         flagdb::update_image_meta($image->pid, array('width' => $size[0], 'height' => $size[1]));
         $file->destruct();
     } else {
         $file->destruct();
         return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>';
     }
     return '1';
 }