Named transformations can be created using the UI or the API. This article will highlight how to transfer the named transformation between accounts using API (using our JAVA SDK).
Copying named transformation will be a 2 step process:
1. List transformation from the source account
2. Create transformation in the destination account using the source account's transformation value
The get transformations method returns the JSON transformation which looks something like this:
info=[{gravity=south, width=500,height=500, crop=crop},{gravity=south, background=white, width=5000, underlay=sample, height=1}]}
Create transformation accepts the transformation parameter as a string, something like this:
"w_500,h_500,g_south,c_crop/b_white,g_north,h_1,u_sample,w_5000"
For rather simpler transformations it is easier to do string manipulation and get the JSON to look like the string format. But with complex transformations this gets tricky.
The best way will be to use “view transformation” (api.transformation), and then use the info property to build a new transformation.
Example:
Map transformation=api.transformation("namedTest", ObjectUtils.emptyMap()); //here namedTest is a named transformation
Response:
{gravity=north, background=white, width=5000, underlay=sample, height=1}, {effect=trim}, {width=iw, crop=crop, height=ih}, {width=iw, crop=pad, height=ih}, {extension=none, effect=trim:10}]}
Doing a get info on the above transformation will return in a string:
String s=new Transformation((List<Map>) transformation.get("info")).generate();
The string response can be directly passed to createTransformation as a parameter:
b_white,g_south,h_1,u_sample,w_5000/e_trim/c_crop,h_ih,w_iw/b_white,g_north,h_1,u_sample,w_5000/e_trim/c_crop,h_ih,w_iw/c_pad,h_ih,w_iw/e_trim:10
Comments
0 comments
Please sign in to leave a comment.