Changeset 13035


Ignore:
Timestamp:
02/05/12 15:58:14 (8 years ago)
Author:
rvelices
Message:

multisize

  • watermarks loaded also from local dir
  • fix/simplify algo for cropping
  • imagick use scaleImage (fast) before resizeImage (slow) if the original is a lot bigger than the requested size
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/derivatives.php

    r13021 r13035  
    6868      $errors[$type]['crop'] = '[0..100]'; 
    6969    } 
    70      
     70 
    7171    if ($v!=0) 
    7272    { 
     
    8282      } 
    8383    } 
    84      
     84 
    8585    if (count($errors)==0) 
    8686    { 
     
    8888      $prev_h = intval($pderivative['h']); 
    8989    } 
    90      
     90 
    9191    $v = intval($pderivative['sharpen']); 
    9292    if ($v<0 || $v>100) 
     
    127127    $watermark->opacity = intval($pwatermark['opacity']); 
    128128    $watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh'])); 
    129      
     129 
    130130    $old_watermark = ImageStdParams::get_watermark(); 
    131     $watermark_changed =  
     131    $watermark_changed = 
    132132      $watermark->file != $old_watermark->file 
    133133      || $watermark->xpos != $old_watermark->xpos 
     
    136136      || $watermark->opacity != $old_watermark->opacity; 
    137137    ImageStdParams::set_watermark($watermark); 
    138      
     138 
    139139    $enabled = ImageStdParams::get_defined_type_map(); 
    140140    $disabled = @unserialize( @$conf['disabled_derivatives'] ); 
     
    144144    } 
    145145    $changed_types = array(); 
    146      
     146 
    147147    foreach(ImageStdParams::get_all_types() as $type) 
    148148    { 
    149149      $pderivative = $pderivatives[$type]; 
    150        
     150 
    151151      if ($pderivative['enabled']) 
    152152      { 
    153153        $new_params = new DerivativeParams( 
    154             new SizingParams(  
     154            new SizingParams( 
    155155              array(intval($pderivative['w']), intval($pderivative['h'])), 
    156156              round($pderivative['crop'] / 100, 2), 
    157157              array(intval($pderivative['minw']), intval($pderivative['minh'])) 
    158               )  
     158              ) 
    159159          ); 
    160160        $new_params->sharpen = intval($pderivative['sharpen']); 
    161161        $new_params->quality = intval($pderivative['quality']); 
    162162        ImageStdParams::apply_global($new_params); 
    163          
     163 
    164164        if (isset($enabled[$type])) 
    165165        { 
     
    172172          } 
    173173 
    174           if ( $same && $new_params->sizing->max_crop != 0  
     174          if ( $same && $new_params->sizing->max_crop != 0 
    175175              && !size_equals($old_params->sizing->min_size, $new_params->sizing->min_size) ) 
    176176          { 
     
    178178          } 
    179179 
    180           if ( $same &&  
     180          if ( $same && 
    181181              ( $new_params->sharpen != $old_params->sharpen 
    182182              || $new_params->quality > $old_params->quality) 
     
    185185            $same = false; 
    186186          } 
    187            
     187 
    188188          if ($same && 
    189             ( $new_params->use_watermark != $old_params->use_watermark  
     189            ( $new_params->use_watermark != $old_params->use_watermark 
    190190             || $new_params->use_watermark && $watermark_changed ) 
    191191            ) 
     
    193193            $same = false; 
    194194          } 
    195            
     195 
    196196          if (!$same) 
    197197          { 
     
    229229        $enabled_by[$type] = $enabled[$type]; 
    230230      } 
    231     }     
     231    } 
    232232    ImageStdParams::set_and_save($enabled_by); 
    233233    if (count($disabled)==0) 
     
    241241    } 
    242242    $conf['disabled_derivatives']=serialize($disabled); 
    243      
     243 
    244244    if (count($changed_types)) 
    245245    { 
     
    299299  } 
    300300  $template->assign('derivatives', $tpl_vars); 
    301    
     301 
    302302  $wm = ImageStdParams::get_watermark(); 
    303303  $template->assign('watermark', array( 
     
    317317  $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH)); 
    318318} 
     319foreach (glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png') as $file) 
     320{ 
     321  $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH)); 
     322} 
    319323$watermark_filemap = array( '' => '---' ); 
    320324foreach( $watermark_files as $file) 
  • trunk/admin/include/image.class.php

    r12956 r13035  
    424424  { 
    425425    $this->image->setInterlaceScheme(Imagick::INTERLACE_LINE); 
     426    if ($this->get_width()%2 == 0 && $this->get_height()%2 == 0 
     427      && $this->get_width() > 3*$width) 
     428    { 
     429      $this->image->scaleImage($this->get_width()/2, $this->get_height()/2); 
     430    } 
    426431    return $this->image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9); 
    427432  } 
  • trunk/include/derivative_params.inc.php

    r13021 r13035  
    7171  } 
    7272 
    73   function crop_h($pixels, $coi, $force) 
     73  function crop_h($pixels, $coi) 
    7474  { 
    7575    if ($this->width() <= $pixels) 
     
    8383      $availableL = $coil > $this->l ? $coil - $this->l : 0; 
    8484      $availableR = $coir < $this->r ? $this->r - $coir : 0; 
    85       if ($availableL + $availableR <= $pixels) 
    86       { 
    87         if (!$force) 
    88         { 
    89           $pixels = $availableL + $availableR; 
    90           $tlcrop = $availableL; 
    91         } 
    92       } 
    93       else 
     85      if ($availableL + $availableR >= $pixels) 
    9486      { 
    9587        if ($availableL < $tlcrop) 
     
    10799  } 
    108100 
    109   function crop_v($pixels, $coi, $force) 
     101  function crop_v($pixels, $coi) 
    110102  { 
    111103    if ($this->height() <= $pixels) 
     
    119111      $availableT = $coit > $this->t ? $coit - $this->t : 0; 
    120112      $availableB = $coib < $this->b ? $this->b - $coib : 0; 
    121       if ($availableT + $availableB <= $pixels) 
    122       { 
    123         if (!$force) 
    124         { 
    125           $pixels = $availableT + $availableB; 
    126           $tlcrop = $availableT; 
    127         } 
    128       } 
    129       else 
     113      if ($availableT + $availableB >= $pixels) 
    130114      { 
    131115        if ($availableT < $tlcrop) 
     
    199183          if ($h < $this->min_size[1]) 
    200184          { 
    201             $idealCropPx = $destCrop->width() - round($destCrop->height() * $this->ideal_size[0] / $this->min_size[1], 0); 
     185            $idealCropPx = $destCrop->width() - floor($destCrop->height() * $this->ideal_size[0] / $this->min_size[1]); 
    202186            $maxCropPx = round($this->max_crop * $destCrop->width()); 
    203             $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi, false); 
     187            $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi); 
    204188          } 
    205189        } 
     
    209193          if ($w < $this->min_size[0]) 
    210194          { 
    211             $idealCropPx = $destCrop->height() - round($destCrop->width() * $this->ideal_size[1] / $this->min_size[0], 0); 
     195            $idealCropPx = $destCrop->height() - floor($destCrop->width() * $this->ideal_size[1] / $this->min_size[0]); 
    212196            $maxCropPx = round($this->max_crop * $destCrop->height()); 
    213             $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi, false); 
     197            $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi); 
    214198          } 
    215199        } 
     
    268252      return array('last_mod_time', 'sizing', 'sharpen', 'quality'); 
    269253  } 
    270      
     254 
    271255  function add_url_tokens(&$tokens) 
    272256  { 
     
    289273    return $this->sizing->ideal_size[1]; 
    290274  } 
    291    
     275 
    292276  function is_identity($in_size) 
    293277  { 
Note: See TracChangeset for help on using the changeset viewer.