Show
Ignore:
Timestamp:
01/12/12 22:37:28 (4 months ago)
Author:
plg
Message:

feature 2548, multiple size:

* adapt the upload script

* remove the resize settings screen

* add a new screen [Administration > Configuration > Options > Photo Sizes]

with the ability to resize original after upload

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_upload.inc.php

    r12831 r12879  
    3333  // default configuration for upload 
    3434  $upload_form_config = array( 
    35     'websize_resize' => array( 
    36       'default' => true, 
    37       'can_be_null' => false, 
    38       ), 
    39      
    40     'websize_maxwidth' => array( 
    41       'default' => 800, 
    42       'min' => 100, 
    43       'max' => 1600, 
    44       'pattern' => '/^\d+$/', 
    45       'can_be_null' => true, 
    46       'error_message' => l10n('The websize maximum width must be a number between %d and %d'), 
    47       ), 
    48    
    49     'websize_maxheight' => array( 
    50       'default' => 600, 
    51       'min' => 100, 
    52       'max' => 1200, 
    53       'pattern' => '/^\d+$/', 
    54       'can_be_null' => true, 
    55       'error_message' => l10n('The websize maximum height must be a number between %d and %d'), 
    56       ), 
    57    
    58     'websize_quality' => array( 
    59       'default' => 95, 
    60       'min' => 50, 
    61       'max' => 100, 
    62       'pattern' => '/^\d+$/', 
    63       'can_be_null' => false, 
    64       'error_message' => l10n('The websize image quality must be a number between %d and %d'), 
    65       ), 
    66    
    67     'thumb_maxwidth' => array( 
    68       'default' => 128, 
    69       'min' => 50, 
    70       'max' => 300, 
    71       'pattern' => '/^\d+$/', 
    72       'can_be_null' => false, 
    73       'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'), 
    74       ), 
    75    
    76     'thumb_maxheight' => array( 
    77       'default' => 96, 
    78       'min' => 50, 
    79       'max' => 300, 
    80       'pattern' => '/^\d+$/', 
    81       'can_be_null' => false, 
    82       'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'), 
    83       ), 
    84    
    85     'thumb_quality' => array( 
    86       'default' => 95, 
    87       'min' => 50, 
    88       'max' => 100, 
    89       'pattern' => '/^\d+$/', 
    90       'can_be_null' => false, 
    91       'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'), 
    92       ), 
    93  
    94     'thumb_crop' => array( 
     35    'original_resize' => array( 
    9536      'default' => false, 
    9637      'can_be_null' => false, 
    9738      ), 
    98  
    99     'thumb_follow_orientation' => array( 
    100       'default' => true, 
    101       'can_be_null' => false, 
    102       ), 
    103    
    104     'hd_keep' => array( 
    105       'default' => true, 
    106       'can_be_null' => false, 
    107       ), 
    108    
    109     'hd_resize' => array( 
    110       'default' => false, 
    111       'can_be_null' => false, 
    112       ), 
    113    
    114     'hd_maxwidth' => array( 
     39   
     40    'original_resize_maxwidth' => array( 
    11541      'default' => 2000, 
    11642      'min' => 500, 
     
    11844      'pattern' => '/^\d+$/', 
    11945      'can_be_null' => false, 
    120       'error_message' => l10n('The high definition maximum width must be a number between %d and %d'), 
     46      'error_message' => l10n('The original maximum width must be a number between %d and %d'), 
    12147      ), 
    12248   
    123     'hd_maxheight' => array( 
     49    'original_resize_maxheight' => array( 
    12450      'default' => 2000, 
    125       'min' => 500, 
     51      'min' => 300, 
    12652      'max' => 20000, 
    12753      'pattern' => '/^\d+$/', 
    12854      'can_be_null' => false, 
    129       'error_message' => l10n('The high definition maximum height must be a number between %d and %d'), 
     55      'error_message' => l10n('The original maximum height must be a number between %d and %d'), 
    13056      ), 
    13157   
    132     'hd_quality' => array( 
     58    'original_resize_quality' => array( 
    13359      'default' => 95, 
    13460      'min' => 50, 
    135       'max' => 100, 
     61      'max' => 98, 
    13662      'pattern' => '/^\d+$/', 
    13763      'can_be_null' => false, 
    138       'error_message' => l10n('The high definition image quality must be a number between %d and %d'), 
     64      'error_message' => l10n('The original image quality must be a number between %d and %d'), 
    13965      ), 
    14066    ); 
     
    17197 
    17298      $updates[] = array( 
    173         'param' => 'upload_form_'.$field, 
     99        'param' => $field, 
    174100        'value' => boolean_to_string($value) 
    175101        ); 
     
    178104    { 
    179105      $updates[] = array( 
    180         'param' => 'upload_form_'.$field, 
     106        'param' => $field, 
    181107        'value' => 'false' 
    182108        ); 
     
    191117      { 
    192118         $updates[] = array( 
    193           'param' => 'upload_form_'.$field, 
     119          'param' => $field, 
    194120          'value' => $value 
    195121          ); 
     
    227153function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null) 
    228154{ 
    229   // Here is the plan 
    230   // 
    231155  // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg 
    232156  // 
    233   // 2) if taller than max_height or wider than max_width, move to pwg_high 
    234   //    + web sized creation 
     157  // 2) keep/resize original 
    235158  // 
    236   // 3) thumbnail creation from web sized 
    237   // 
    238   // 4) register in database 
     159  // 3) register in database 
    239160   
    240161  // TODO 
     
    248169  if (isset($image_id)) 
    249170  { 
    250     // we are performing an update 
     171    // this photo already exists, we update it 
    251172    $query = ' 
    252173SELECT 
     
    317238  } 
    318239 
    319   if ($conf['upload_form_websize_resize'] 
    320       and need_resize($file_path, $conf['upload_form_websize_maxwidth'], $conf['upload_form_websize_maxheight'])) 
    321   { 
    322     $high_path = file_path_for_type($file_path, 'high'); 
    323     $high_dir = dirname($high_path); 
    324     prepare_directory($high_dir); 
    325      
    326     rename($file_path, $high_path); 
    327     $high_infos = pwg_image_infos($high_path); 
    328      
    329     $img = new pwg_image($high_path); 
    330  
    331     $img->pwg_resize( 
    332       $file_path, 
    333       $conf['upload_form_websize_maxwidth'], 
    334       $conf['upload_form_websize_maxheight'], 
    335       $conf['upload_form_websize_quality'], 
    336       $conf['upload_form_automatic_rotation'], 
    337       false 
    338       ); 
    339  
    340     if ($img->library != 'gd') 
    341     { 
    342       if ($conf['upload_form_hd_keep']) 
     240  if (pwg_image::get_library() != 'gd') 
     241  { 
     242    if ($conf['original_resize']) 
     243    { 
     244      $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']); 
     245       
     246      if ($need_resize) 
    343247      { 
    344         if ($conf['upload_form_hd_resize']) 
    345         { 
    346           $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); 
     248        $img = new pwg_image($file_path); 
     249             
     250        $img->pwg_resize( 
     251          $file_path, 
     252          $conf['original_resize_maxwidth'], 
     253          $conf['original_resize_maxheight'], 
     254          $conf['original_resize_quality'], 
     255          $conf['upload_form_automatic_rotation'], 
     256          false 
     257          ); 
    347258         
    348           if ($need_resize) 
    349           { 
    350             $img->pwg_resize( 
    351               $high_path, 
    352               $conf['upload_form_hd_maxwidth'], 
    353               $conf['upload_form_hd_maxheight'], 
    354               $conf['upload_form_hd_quality'], 
    355               $conf['upload_form_automatic_rotation'], 
    356               false 
    357               ); 
    358             $high_infos = pwg_image_infos($high_path); 
    359           } 
    360         } 
     259        $img->destroy(); 
    361260      } 
    362       else 
    363       { 
    364         unlink($high_path); 
    365         $high_infos = null; 
    366       } 
    367     } 
    368     $img->destroy(); 
     261    } 
    369262  } 
    370263 
    371264  $file_infos = pwg_image_infos($file_path); 
    372265   
    373   $thumb_path = file_path_for_type($file_path, 'thumb'); 
    374   $thumb_dir = dirname($thumb_path); 
    375   prepare_directory($thumb_dir); 
    376  
    377   $img = new pwg_image($file_path); 
    378   $img->pwg_resize( 
    379     $thumb_path, 
    380     $conf['upload_form_thumb_maxwidth'], 
    381     $conf['upload_form_thumb_maxheight'], 
    382     $conf['upload_form_thumb_quality'], 
    383     false, 
    384     true, 
    385     $conf['upload_form_thumb_crop'], 
    386     $conf['upload_form_thumb_follow_orientation'] 
    387     ); 
    388   $img->destroy(); 
    389    
    390   $thumb_infos = pwg_image_infos($thumb_path); 
    391  
    392266  if (isset($image_id)) 
    393267  { 
    394268    $update = array( 
    395       'id' => $image_id, 
    396269      'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 
    397270      'filesize' => $file_infos['filesize'], 
     
    402275      ); 
    403276     
    404     if (isset($high_infos)) 
    405     { 
    406       $update['has_high'] = 'true'; 
    407       $update['high_filesize'] = $high_infos['filesize']; 
    408       $update['high_width'] = $high_infos['width']; 
    409       $update['high_height'] = $high_infos['height']; 
    410     } 
    411     else 
    412     { 
    413       $update['has_high'] = 'false'; 
    414       $update['high_filesize'] = null; 
    415       $update['high_width'] = null; 
    416       $update['high_height'] = null; 
    417     } 
    418  
    419277    if (isset($level)) 
    420278    { 
     
    422280    } 
    423281 
    424     mass_updates( 
     282    single_update( 
    425283      IMAGES_TABLE, 
    426       array( 
    427         'primary' => array('id'), 
    428         'update' => array_keys($update) 
    429         ), 
    430       array($update) 
     284      $update, 
     285      array('id' => $image_id) 
    431286      ); 
    432287  } 
     
    458313      $insert['level'] = $level; 
    459314    } 
    460    
    461     mass_inserts( 
    462       IMAGES_TABLE, 
    463       array_keys($insert), 
    464       array($insert) 
    465       ); 
     315 
     316    single_insert(IMAGES_TABLE, $insert); 
    466317   
    467318    $image_id = pwg_db_insert_id(IMAGES_TABLE);