-
Notifications
You must be signed in to change notification settings - Fork 2
Examples
Paul Filitchkin edited this page Mar 16, 2016
·
4 revisions
import json
from subprocess import Popen, PIPE
resize_operation = {
'type': 'resize',
'params':
{
'width': 100,
'height': 1000,
'type': 'width',
'quality': 85,
'output_url': 'file://output.jpg'
}
}
input_dict = {'input_url': 'file://input.jpg',
'correct_rotation': True,
'operations': [resize_operation]}
input_string = json.dumps(input_dict, separators=(',',':'))
p = Popen(["arion", "--input", input_string], stdout=PIPE)
cmd_output = p.communicate()
result = json.loads(cmd_output[0])
if result['result'] != True:
print 'Failed to resize image'
$operations = [
[
'type' => 'resize',
'params' =>
[
'width' => 100,
'height' => 1000,
'type' => 'width',
'quality' => 80,
'output_url' => 'file://output.jpg'
]
]
];
$input = ['input_url' => 'file://' . $temp_original_path,
'correct_rotation' => $correct_rotation,
'operations' => $operations];
$cmd = "arion '" . json_encode($input) . "'";
$raw_response = shell_exec($cmd);
$response = json_decode($raw_response, true);
if ($response['result'] !== true)
{
throw new Exception('Failed to resize image');
}
operations = [
{
type: 'resize',
params:
{
width: 100,
height: 1000,
type: 'width',
quality: 85,
output_url: 'file://output.jpg'
}
}
]
input = {input_url: 'file://input.jpg',
correct_rotation: true,
operations: operations}
cmd = "arion --input '" + input.to_json() +"'"
result_json = `#{cmd}`
result = JSON.parse(result_json)
if (result['result'] != true)
raise 'Failed to resize image'
end
# Create a text file with the JSON command
>$ vim input.json
>$ cat input.json
{
"input_url": "file://input.jpg",
"correct_rotation":true,
"operations": [
{
"type": "resize",
"params": {
"type": "width",
"width": 100,
"height": 1000,
"quality": 85,
"output_url": "file://output.jpg"
}
}
]
}
>$ arion --input "`cat input.json`"