filename = "try.png";
#debug_str = "";
close all
graphics_toolkit("gnuplot")
#graphics_toolkit("qt")
#graphics_toolkit("fltk")
plot(1:10)
paperposition = get(gcf, "paperposition");

printf("PNG simplest print... ")
#print(filename, "-debug")
print(filename)
info = imfinfo(filename);
tolerance = 0.01;
resolution = 150;
# by default, resolution is 150 ppi
assert(info.XResolution, resolution / 2.54, tolerance);
assert(info.YResolution, resolution / 2.54, tolerance);
assert(info.Width, paperposition(3) * resolution, tolerance)
assert(info.Height, paperposition(4) * resolution, tolerance)
printf("PASSED\n")

printf("PNG with resolution... ")
resolution = 300;
print(filename, sprintf("-r%d", resolution))
info = imfinfo(filename);
tolerance = 0.01;
# by default, resolution is 150 ppi
assert(info.XResolution, resolution / 2.54, tolerance);
assert(info.YResolution, resolution / 2.54, tolerance);
assert(info.Width, paperposition(3) * resolution, tolerance)
assert(info.Height, paperposition(4) * resolution, tolerance)
printf("PASSED\n")

printf("PNG with -r0... ")
print(filename, "-r0")
info = imfinfo(filename);
tolerance = 0.01;
# -0 => resolution should be screen ppi
resolution = get(0, "screenpixelsperinch");
assert(info.XResolution, resolution / 2.54, tolerance);
assert(info.YResolution, resolution / 2.54, tolerance);
assert(info.Width, round(paperposition(3) * resolution))
assert(info.Height, round(paperposition(4) * resolution))
printf("PASSED\n")

printf("PNG with size... ")
sz = [1000, 800];
print(filename, sprintf("-S%g,%g", sz))
info = imfinfo(filename);
tolerance = 0.01;
assert(info.Width, sz(1))
assert(info.Height, sz(2))
printf("PASSED\n")
