Generate imagecaches on the fly

WE HAVE MOVED!

Please visit our new Drupal Website at https://www.xenyo.com我們的新網頁設計公司網頁.

<?php
/** drupal 7 **/
$presetname = '800x421'; //presetname
$src = $image->uri; 
$dst = image_style_path($presetname, $src); //create image uri
if(!file_exists($dst)) {
  image_style_create_derivative(image_style_load($presetname), $src, $dst)); // create imagecache 
}
/** drupal 6 **/
$presetname = '800x421';
$preset = imagecache_preset_by_name($presetname);
$src = $image["filepath"];
$dst = imagecache_create_path($presetname, $src);
if(!file_exists($dst)) {
 imagecache_build_derivative($preset['actions'], $src, $dst)) ;
}
?>
Help Share this Article