Ticket #560: image_proportion.diff

File image_proportion.diff, 2.4 kB (added by Lipki, 9 months ago)
  • function.image.php

    old new  
    1717 * alt :string 
    1818 * width :uint 
    1919 * height :uint 
     20 * maxwidth :uint only with maxheight 
     21 * maxheight :uint only with maxwidth 
    2022 * zoom 1-100 
    2123 * omo :boolean 
    2224 * alignh [left|center|right|:int] 
     
    8183     
    8284    // Cache and make changes if necessary. 
    8385    if( is_file($origine_path) && !is_file($cache_path) ) { 
    84         $att = array('width'=>'', 'height'=>'', 'zoom'=>'', 'alignh'=>'', 'alignv'=>'', 'ext'=>'', 'quality'=>'', 'shadow'=>''); 
     86        $att = array('width'=>'', 'height'=>'', 'maxwidth'=>'', 'maxheight'=>'', 'zoom'=>'', 'alignh'=>'', 'alignv'=>'', 'ext'=>'', 'quality'=>'', 'shadow'=>''); 
    8587        if( count(array_intersect_key($params, $att)) ) 
    8688            jtpl_function_html_image_inCache($src, $cachename, $params); 
    8789    } 
     
    9496    if( !is_file($cache_path) ) { 
    9597        $att['src'] = $origine_www; 
    9698        $att['style'] = empty($att['style'])?'':$att['style']; 
    97         if( !empty($params['width']) )     $att['style'] .= 'width: '.$params['width'].'px;'; 
    98         if( !empty($params['height']) ) $att['style'] .= 'height: '.$params['height'].'px;'; 
     99        if( !empty($params['width']) )             $att['style'] .= 'width: '.$params['width'].'px;'; 
     100        else if( !empty($params['maxwidth']) )     $att['style'] .= 'width: '.$params['maxwidth'].'px;'; 
     101        if( !empty($params['height']) )            $att['style'] .= 'height: '.$params['height'].'px;'; 
     102        else if( !empty($params['maxheight']) )    $att['style'] .= 'height: '.$params['maxheight'].'px;'; 
    99103    } else 
    100104        $att['src'] = $cache_www; 
    101105     
     
    132136        default                      : return ; 
    133137    } 
    134138     
     139    if(!empty($array['maxwidth']) && !empty($array['maxheight'])) { 
     140         
     141        $rapy = imagesy($image)/$array['maxwidth']; 
     142        $rapx = imagesx($image)/$array['maxheight']; 
     143         
     144        if( $rapy > $rapx ) { 
     145            $array['height'] = $array['maxheight']; 
     146            $array['width'] = imagesx($image)/$rapy; 
     147        } else { 
     148            $array['width'] = $array['maxwidth']; 
     149            $array['height'] = imagesy($image)/$rapx; 
     150        } 
     151    } 
     152     
    135153    if (!empty($array['width']) || !empty($array['height'])) { 
    136154     
    137155        $ancienimage = $image; 
Download in other formats: Original Format