स्क्रॉल
छवि प्रीसेट्स का प्रोग्रामेटिक उपयोग (programmatically use imagecache)
Drupal 6 की तुलना में, जहाँ हम imagecache मॉड्यूल का उपयोग करते थे, Drupal 7 में Image API थोड़ा बदल गया है। Drupal 6 में हम प्रीसेट (preset) को प्रोग्रामmatically इस तरह उपयोग कर सकते थे:
<?php print theme('imagecache', 'my_preset', $file_path, $alt, $title, $attributes); ?>
उदाहरण के लिए:
theme('imagecache', '300x300crop', $first_photo["filepath"], $node->title, $node->title, array('itemprop' => 'image'));
लेकिन Drupal 7 में हम कोड थोड़ा अलग तरीके से लिखते हैं:
print theme_image_style(array( 'style_name' => 'home_category_image', 'path' => $result['node']->field_image['und'][0]['uri'], 'alt' => $title, 'width' => '', 'height' => '', 'attributes' => array('class' => 'search-result-img'), ));
अब हम theme_image_style() फ़ंक्शन का उपयोग करते हैं और एक ऐरे (array) में मान पास करते हैं:
- style_name — यह इमेज स्टाइल (preset) का नाम होता है।
- path — छवि का URI पथ होता है, जैसे: public://product/421-a1 amt.jpg, जहाँ public एक सार्वजनिक (public) फ़ाइल सिस्टम को दर्शाता है।
- alt — छवि का alt टेक्स्ट।
- width, height — इन्हें छोड़ा जा सकता है, लेकिन इन्हें न जोड़ने से कभी-कभी notice उत्पन्न हो सकता है।
- attributes — HTML गुणों (attributes) का एक ऐरे, जैसे class या itemprop।