Anatomography Web API サンプルコード - Perl - 画像サイズ・背景色指定・背景透明化はじめに画像の出力サイズ、背景色、背景透明度などの指定をします。 サンプルコード出力先ファイルは適宜変更して下さい。
#!/usr/bin/env perl
use strict;
use LWP::UserAgent;
# リクエスト先URL
my $serverURL = "http://lifesciencedb.jp/bp3d/API/";
# 描画リクエスト用のJSON文字列を作成(背景浅葱色)
my $json = <<JSON;
{
"Common" : {
"Version":"4.0",
"TreeName":"partof"
},
"Window" : {
"ImageWidth":200,
"ImageHeight":300,
"BackgroundColor":"00A4AC"
},
"Part":[
{
"PartName":"Human body"
}
]
}
JSON
# 出力(背景浅葱色)
open OUT, ">windowproperties01.png";
binmode(OUT);
print OUT &getImage($json); # 作成したJSONを利用して描画リクエスト
close OUT;
# 描画リクエスト用のJSON文字列を作成(背景透明化)
my $json2 = <<JSON;
{
"Common" : {
"Version":"4.0",
"TreeName":"partof"
},
"Window" : {
"ImageWidth":200,
"ImageHeight":300,
"BackgroundColor":"00A4AC",
"BackgroundOpacity":0
},
"Part":[
{
"PartName":"Human body"
}
]
}
JSON
# 出力(背景透明化)
open OUT, ">windowproperties02.png";
binmode(OUT);
print OUT &getImage($json2); # 作成したJSONを利用して描画リクエスト
close OUT;
# 生成したJSONをパラメータとしてimageに対してGETリクエストするサブルーチン
sub getImage () {
my $json = shift;
my $userAgent = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET', $serverURL."image?".$json);
my $response = $userAgent->request($request);
return $response->content;
}
出力画像 背景浅葱色 ![]() ![]() Window項目の設定(背景浅葱色)
# 描画リクエスト用のJSON文字列を作成(背景浅葱色)
my $json = <<JSON;
{
"Common" : {
"Version":"4.0",
"TreeName":"partof"
},
"Window" : {
"ImageWidth":200,
"ImageHeight":300,
"BackgroundColor":"00A4AC"
},
"Part":[
{
"PartName":"Human body"
}
]
}
JSON
ImageWidthで画像横幅を200pxに、ImageHeightと画像高さを300pxにしています。 BackgroundColorで背景色を"00A4AC"(浅葱色)にしています。 Partとしては"Human body"のみを指定しています。 Window項目の設定(背景浅葱色)
# 描画リクエスト用のJSON文字列を作成(背景透明化)
my $json = <<JSON;
{
"Common" : {
"Version":"4.0",
"TreeName":"partof"
},
"Window" : {
"ImageWidth":200,
"ImageHeight":300,
"BackgroundColor":"00A4AC",
"BackgroundOpacity":0
},
"Part":[
{
"PartName":"Human body"
}
]
}
JSON
ImageWidthで画像横幅を200pxに、ImageHeightと画像高さを300pxにしています。 BackgroundColorで背景色を"00A4AC"(浅葱色)にし、背景の不透明度を0(透明)にしています。 Partとしては"Human body"のみを指定しています。 |