Update drupal6 Imagecache presets to Drupal7 's image styles_php tutorial

Source: Internet
Author: User
Tags drupal
Because the Imagecache preset in DRUPAL6 has been integrated into the core of DRUPAL7, the next solution is Vladimir, you need to create a PHP file under your Drupal root directory and copy the following code to execute the file .


[PHP]
Define (' Drupal_root ', GETCWD ());
Require_once

Drupal_root. '/includes/bootstrap.inc ';
Drupal_bootstrap (Drupal_bootstrap_full);
/////////////////////////////////////////////////
function Imagecache_preset_actions ($preset, $reset = FALSE) {
$actions _cache = Array ();


$result = Db_query (' SELECT * from {imagecache_action} where Presetid = '. $preset [' Presetid ']. ' ORDER by weight ');
foreach ($result as $row) {
$row = (array) $row;
$row [' data '] = unserialize ($row [' data ']);
$actions _cache[$preset [' Presetid ']][] = $row;
}
Return Isset (

$actions _cache[$preset [' Presetid ']]? $actions _cache[$preset [' Presetid ']: Array ();
}
/////////////////////////////////////////////////
/////////////////////////////////////////////////

function Imagecache_presets () {
$presets = Array ();


$normal _presets = Array ();


$result = Db_query (' SELECT * from {imagecache_preset} ORDER by Presetname ');

foreach ($result as $preset) {
$preset = (array) $preset;
$presets [$preset [' presetid ']] = $preset;
$presets [$preset [' Presetid ']][' actions '] = Imagecache_preset_actions ($preset);
$presets [$preset [' Presetid ']][' storage '] = 0;


Collect Normal preset names so we can skip defaults and mark overrides accordingly
$normal _presets[$preset [' presetname ']] = $preset [' Presetid '];
}
Return

$presets;
}
/////////////////////////////////////////////////
/////////////////////////////////////////////////

$styles _cnt=0;
$effects _new_cnt=0;
$effects _ext_cnt=0;
$presets =imagecache_presets ();
foreach ($presets as $preset)
{
$styles _cnt++;//Inc Styles

$style =image_style_load ($preset [' presetname ']);

$style [' name ']= $preset [' Presetname '];
$style =image_style_save ($style);
if (!isset ($style [' effects ')])
{
$style [' Effects ']=array ();
}
foreach ($preset [' actions '] as $action)
{
$action [' Action ']=str_replace (' imagecache ', ' image ', $action [' action ']);
$action [' Module ']=str_replace (' imagecache ', ' image ', $action [' module ']);

$effect _ieid=false;//effect NOT exists
foreach ($style [' effects '] as $effect)
{
if ($effect [' name '] = = $action [' Action '] &&
$effect [' module '] = = $action [' module '] &&
$effect [' weight '] = = $action [' Weight '] &&
$effect [' data '] = = $action [' Data ']
{
$effect _ieid= $effect [' Ieid '];//effect exists
}
}
$effect =array ();
if ($effect _ieid)
{
$effects _ext_cnt++;//Inc exists
$effect =image_effect_load ($effect _ieid, $style [' name ']);
}
Else
{
$effects _new_cnt++;//Inc New
$effect =image_effect_definition_load ($action [' action ']);
}

$effect [' isid '] = $style [' Isid '];

$effect [' name '] = $action [' Action '];
$effect [' module '] = = $action [' module '];
$effect [' weight '] = $action [' Weight '];
$effect [' data '] = $action [' Data '];
$effect = Image_effect_save ($effect);
$style [' Effects '] [$effect [' Ieid ']] = $effect;
}
$style =image_style_save ($style);
}
Print

"Styles: $styles _cnt, effects new: $effects _new_cnt, effects exists: $effects _ext_cnt \ n";
?>

Define (' Drupal_root ', GETCWD ());
Require_once

Drupal_root. '/includes/bootstrap.inc ';
Drupal_bootstrap (Drupal_bootstrap_full);
/////////////////////////////////////////////////
function Imagecache_preset_actions ($preset, $reset = FALSE) {
$actions _cache = Array ();

$result = Db_query (' SELECT * from {imagecache_action} where Presetid = '. $preset [' Presetid ']. ' ORDER by weight ');
foreach ($result as $row) {
$row = (array) $row;
$row [' data '] = unserialize ($row [' data ']);
$actions _cache[$preset [' Presetid ']][] = $row;
}
Return Isset (

$actions _cache[$preset [' Presetid ']]? $actions _cache[$preset [' Presetid ']: Array ();
}
/////////////////////////////////////////////////
/////////////////////////////////////////////////

function Imagecache_presets () {
$presets = Array ();

$normal _presets = Array ();

$result = Db_query (' SELECT * from {imagecache_preset} ORDER by Presetname ');

foreach ($result as $preset) {
$preset = (array) $preset;
$presets [$preset [' presetid ']] = $preset;
$presets [$preset [' Presetid ']][' actions '] = Imagecache_preset_actions ($preset);
$presets [$preset [' Presetid ']][' storage '] = 0;

Collect Normal preset names so we can skip defaults and mark overrides accordingly
$normal _presets[$preset [' presetname ']] = $preset [' Presetid '];
}
Return

$presets;
}
/////////////////////////////////////////////////
/////////////////////////////////////////////////

$styles _cnt=0;
$effects _new_cnt=0;
$effects _ext_cnt=0;
$presets =imagecache_presets ();
foreach ($presets as $preset)
{
$styles _cnt++;//Inc Styles

$style =image_style_load ($preset [' presetname ']);

$style [' name ']= $preset [' Presetname '];
$style =image_style_save ($style);
if (!isset ($style [' effects ')])
{
$style [' Effects ']=array ();
}
foreach ($preset [' actions '] as $action)
{
$action [' Action ']=str_replace (' imagecache ', ' image ', $action [' action ']);
$action [' Module ']=str_replace (' imagecache ', ' image ', $action [' module ']);

$effect _ieid=false;//effect NOT exists
foreach ($style [' effects '] as $effect)
{
if ($effect [' name '] = = $action [' Action '] &&
$effect [' module '] = = $action [' module '] &&
$effect [' weight '] = = $action [' Weight '] &&
$effect [' data '] = = $action [' Data ']
{
$effect _ieid= $effect [' Ieid '];//effect exists
}
}
$effect =array ();
if ($effect _ieid)
{
$effects _ext_cnt++;//Inc exists
$effect =image_effect_load ($effect _ieid, $style [' name ']);
}
Else
{
$effects _new_cnt++;//Inc New
$effect =image_effect_definition_load ($action [' action ']);
}

$effect [' isid '] = $style [' Isid '];

$effect [' name '] = $action [' Action '];
$effect [' module '] = = $action [' module '];
$effect [' weight '] = $action [' Weight '];
$effect [' data '] = $action [' Data '];
$effect = Image_effect_save ($effect);
$style [' Effects '] [$effect [' Ieid ']] = $effect;
}
$style =image_style_save ($style);
}
Print

"Styles: $styles _cnt, effects new: $effects _new_cnt, effects exists: $effects _ext_cnt \ n";
? >happy drupalling

http://www.bkjia.com/PHPjc/477273.html www.bkjia.com true http://www.bkjia.com/PHPjc/477273.html techarticle because the Imagecache preset in DRUPAL6 has been integrated into the core of DRUPAL7, the next solution is Vladimir, you need to create a ph under your Drupal root directory ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.