Posted by Nicolas Bredefeldt on February 8, 2010 at 6:23pm
15 followers
| Project: | ImageCache |
| Version: | 6.x-2.x-dev |
| Component: | imagecache_image module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
There is an "export" feature in the imagecache UI... but I can't seem to get the "import" the things I've exported from imagecache... I would love to be able to export and import imagecache presets the same way I can do with views or cck.
Or am I missing something?
Comments
#1
It would look something like this: I added this to my module file called site_config.module
function site_config_imagecache_default_presets() {$presets = array();
$presets['thumb2'] = array (
'presetname' => 'thumb2',
'actions' =>
array (
0 =>
array (
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_scale',
'data' =>
array (
'width' => '',
'height' => '150',
'upscale' => 1,
),
),
1 =>
array (
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_crop',
'data' =>
array (
'width' => '200',
'height' => '150',
'xoffset' => 'center',
'yoffset' => 'top',
),
),
),
);
return $presets;
}
#2
I think this function are very usefull.
By example i have create a preset with a custom action in php, this action is not exactly the good action but contains many code. I don't want use her in a active preset but i want save her. I can't now.
So, import is too usefull for people who cannot use the file system, and can't place code on the module directory, with preset import they could copy one preset from one site to another.
Another usefull use case is the creation of place to share preset.
#3
I thinks that this feature is very useful. Since there is export feature for quite some time is there any particular reason why it hasn't been implemented before?
#4
Seems that right now the only way is to export and import the table record.
imagecache_action
imagecache_preset
#5
Marked as duplicate of this issue: #872658: Would be nice: Clone preset option.
#6
subscribe
#7
Trying to import with method mentioned in #1 but can not find site_config.module file. Am i missing something?
#8
@lameei - "site_config" is a custom module on arcane's site. You will need to add a similar function to your own custom module. Read
"mymodule" where you see "site_config" in arcane's post.
#9
Subscribing.
#10
+1
#11
Seems odd that you can export but not import. What can you do with the export?
#12
Subscribe
#13
Yes definitely need either clone or import.
Cheers
#14
You can already import the presets easily if you have the ability to execute php code.
//lines you copied from the export page
$presets = array(); $presets['importy_preset'] = array ( 'presetname' => 'importy_preset', 'actions' => array ( 0 => array ( 'weight' => '0', 'module' => 'imagecache', 'action' => 'imagecache_scale_and_crop', 'data' => array ( 'width' => '100', 'height' => '100', ), ), ), );
//lines to loop through and save the presets.
foreach ($presets as $preset){
imagecache_preset_save($preset);
}
You could do this on a page with the php input filter (only load the page one time) or you could use any other method of running arbitrary php a single time.
The current export code isn't perfect because it doesn't include the "return $presets;" line for including in your own module, and you would need to remove the "$presets = array();" line to paste multiple exports together.
Ideally, the export code could remove the "$presets = array();" line
then the import page could have a single text area where you could paste multiple exported presets
The import page would then run
$presets = array();
// code from the text area
foreach ($presets as $preset){
imagecache_preset_save($preset);
}
#15
sub
#16
Hi,
any news on this ? Is there something impossible/difficult ?
I tried the #14 solution but had some problems with it. The imported presets had empty actions...
If some people have code for this it would be nice to post it here. thanks.
#17
I have just used this code for importing preset and it worked perfectly. I user devel module to execute the php code.
<?php
$template = array (); /* put exported preset array here */
/* Create a new preset from export */
$preset = imagecache_preset_save( array('presetname' => $template['presetname']) );
/* Create actions for that preset */
$preset['actions'] = $template['actions'];
foreach( $preset['actions'] as $action ){
$action['presetid'] = $preset['presetid'];
imagecache_action_save($action);
}
?>
#18
Ok, here is a patch that should add an import page
I added a permission for importing, because the current code simply runs eval() on the entered text. This is a security concern so only give that permission to trusted users.
This is the first patch I have created so hopefully it turns out correctly.
#19
Making title more descriptive/findable.
#20
i try your patch but i've not the ability to import a preset, as admin, idem if i check the permission for authanticated user...run cron and flush cache does nothing..
admin/build/imagecache/import go to edit preset name => Edit preset: !presetname
so i'm not able to import a preset..
#21
I am not sure what is happening when you use the patch.
You are able to go to admin/build/imagecache/import and paste the code generated from an export?
I didn't understand what you meant by:
"admin/build/imagecache/import go to edit preset name => Edit preset: !presetname"
This patch does slightly alter the export code, so if you have a saved export you would need to change it from:
$presets = array(); $presets['importy_preset'] = ...to
$preset['importy_preset'] = ...#22
After restart apache , all is good, admin/build/imagecache/import give me a blank textfield to paste my export preset..and i've the sub-menu item to import in admin menu...i will test but all seem good for now
do you think this feature will be implemented in future imagecache release ? if yes , have you an idea about time to,day,week,month ..?
#23
I feel it is unlikely any pending patches will be committed soon. Even if they are, it may be a long time before another release is made. Currently, the best bet is to use the dev version and then go the the "pending patches" and apply any that you need.
If this patch works for you, feel free to update and change the status to reviewed and tested. If the patches ever are committed it might help.
#24
this patch on dev version cause this error :
Fatal error: Cannot use object of type stdClass as array in ../sites/all/modules/imagecache/imagecache.module on line 1123line :
<?php$presetdir = realpath(file_directory_path() .'/imagecache/'. $preset['presetname']);
?>
after manually patch because doesn't work on ubuntu.
on admin/build/imagecache , preset is there but empty and with a blank name
so need work to be ok.
#25
new test on beta12 patched , and preset import work well.On the UI it would be great to have access of all imagecache sub-menus on
admin/build/imagecache/*andadmin/build/imagecache/*/exportlike onadmin/build/imagecache/listdon't know if is necessary to save the preset after import like with views..for me it's ok.