theming image with style

Как лесно да манипулираме изображения със създадените в сайта стилове? Изхода може директно да отпечатаме в който и да е .tpl.php или да го върнем в променлива от функция в модул или templdte.php.
Следващия код показва как да отпечатаме изхода директно в node.tpl.php.

      $node = $content['body']['#object'];
      foreach ($node -> field_picture['und'] AS $k => $val) {
 
        $orientation = array('profile_landscape', 'profile_first_pic');
        $presset = '';
        $val['width'] == 580 ? $presset = $orientation[0] : $presset = $orientation[1];
 
        if ($k > 0) {
          $class_first = '';
          $k == 1 ? $class_first = ' first' : NULL;
          print theme_image_style(array('style_name' => $presset,  'path' =>  $val['uri'], 'width' => $val['width'], 'height' => $val['height'], 'attributes' => array('class' => $presset . $class_first)));
        }
      }

Това се случва от последния print,

print theme_image_style(array('style_name' => $presset,  'path' =>  $val['uri'], 'width' => $val['width'], 'height' => $val['height'], 'attributes' => array('class' => $presset . $class_first)));

докато останалия код отпечатва снимките след първата съобразно тяхната ориентация (пейзаж / портрет), като сравнява по конкретна (580px) ширина. Предварително сме създали стилове с размерите за ориентация портрет(profile_first_pic) и пейзаж(profile_landscape). Стила за първата снимка profile_first_pic е портрет. Нея показваме преди останалите.

print theme_image_style(array('style_name' => 'profile_first_pic',  'path' =>  $node -> field_picture['und'][0]['uri'], 'width' => $node -> field_picture['und'][0]['width'], 'height' => $node -> field_picture['und'][0]['height'], 'attributes' => array('class' => 'profile-bio-pic')));
Categories: