Use « montage » for picture with camera and lens

This commit is contained in:
Antoine Van Elstraete 2018-11-20 21:34:28 +01:00 committed by Antoine Van Elstraete
parent ba384dd41b
commit 7c41436541

View File

@ -11,7 +11,7 @@ import locale
from os.path import isfile
from tempfile import mkdtemp
from shutil import copyfile, rmtree
from subprocess import run
from subprocess import run, CalledProcessError
def i18n(language):
@ -145,7 +145,7 @@ def general(informations, language, colors, temp_dir):
'bar_width': 0.8
},
temp_dir + "/picnb_datetime.pdf")
text += ".. figure:: picnb_datetime.pdf\n\t:width: 16cm\n"
text += ".. figure:: picnb_datetime.pdf\n\t:width: 16cm\n\n"
return text
@ -194,12 +194,15 @@ def camera_and_lens(informations, language, colors, temp_dir):
copyfile(
"helpers/cameras/{}.jpg".format(top_camera.replace(" ", "_").replace("/", "_")),
"{}/{}.jpg".format(temp_dir, top_camera.replace(" ", "_").replace("/", "_")))
text += ".. image:: {}.jpg\n\t:width: 8cm\n\t:align: left\n".format(top_camera.replace(" ", "_").replace("/", "_"))
image1 = "{}/{}.jpg".format(temp_dir, top_camera.replace(" ", "_").replace("/", "_"))
if isfile("helpers/lenses/{}.jpg".format(top_lens.replace(" ", "_").replace("/", "_"))):
copyfile(
"helpers/lenses/{}.jpg".format(top_lens.replace(" ", "_").replace("/", "_")),
"{}/{}.jpg".format(temp_dir, top_lens.replace(" ", "_").replace("/", "_")))
text += ".. image:: {}.jpg\n\t:width: 8cm\n\t:align: right\n".format(top_lens.replace(" ", "_").replace("/", "_"))
image2 = "{}/{}.jpg".format(temp_dir, top_lens.replace(" ", "_").replace("/", "_"))
if image1 or image2:
run(["montage", image1, image2, "-geometry", "+10+0", "-quality", "94", "{}/top_camera_lens.jpg".format(temp_dir)], check=True)
text += ".. image:: {}.jpg\n\t:height: 5cm\n\n".format("top_camera_lens")
if len(informations['cameras']) > 1:
pie(
{
@ -213,7 +216,7 @@ def camera_and_lens(informations, language, colors, temp_dir):
},
temp_dir + "/cameras_parts.pdf")
text += "\n\n"
text += ".. figure:: cameras_parts.pdf\n\t:width: 17cm\n"
text += ".. figure:: cameras_parts.pdf\n\t:width: 17cm\n\n"
if len(informations['lenses']) > 1:
pie(
{
@ -227,7 +230,7 @@ def camera_and_lens(informations, language, colors, temp_dir):
},
temp_dir + "/lenses_parts.pdf")
text += "\n\n"
text += ".. figure:: lenses_parts.pdf\n\t:width: 17cm\n"
text += ".. figure:: lenses_parts.pdf\n\t:width: 17cm\n\n"
return text
@ -255,7 +258,7 @@ def focal_aperture(informations, language, colors, temp_dir):
'title': _("Focals{}").format(_(" : top 20") if len(top_focals) == 20 else "")
},
temp_dir + "/focal_lenghts.pdf")
text += ".. figure:: focal_lenghts.pdf\n\t:width: 17cm\n"
text += ".. figure:: focal_lenghts.pdf\n\t:width: 17cm\n\n"
else:
text += _("Only one focal lenght is used : {}mm. ").format(float(sorted(informations['focals'], key=informations['focals'].get)[0]))
text += "\n\n"
@ -279,7 +282,7 @@ def focal_aperture(informations, language, colors, temp_dir):
'title': _("Apertures{}").format(_(" : top 20") if len(top_apertures) == 20 else "")
},
temp_dir + "/apertures.pdf")
text += ".. figure:: apertures.pdf\n\t:width: 17cm\n"
text += ".. figure:: apertures.pdf\n\t:width: 17cm\n\n"
else:
text += _("Only one aperture is used : {}{}. ").format(
_("F"),
@ -310,7 +313,7 @@ def iso_shutter(informations, language, colors, temp_dir):
'title': _("ISO sensibilities{}").format(_(" : top 20") if len(top_isos) == 20 else "")
},
temp_dir + "/isos.pdf")
text += ".. figure:: isos.pdf\n\t:width: 17cm\n"
text += ".. figure:: isos.pdf\n\t:width: 17cm\n\n"
else:
text += _("All shots at the same sensitivity : ISO {} ").format(sorted(informations['isos'], key=informations['isos'].get)[0])
text += "\n\n"
@ -334,7 +337,7 @@ def iso_shutter(informations, language, colors, temp_dir):
'title': _("Shutter speeds{}").format(_(" : top 20") if len(top_shutter_speeds) == 20 else "")
},
temp_dir + "/speeds.pdf")
text += ".. figure:: speeds.pdf\n\t:width: 17cm\n"
text += ".. figure:: speeds.pdf\n\t:width: 17cm\n\n"
else:
text += _("All shots at the same speed : {}. ").format(format_shutter_speed(sorted(informations['shutter_speeds'], key=informations['shutter_speeds'].get)[0]))
return text
@ -375,7 +378,7 @@ def create(informations, language, output_file):
with open(temp_dir + "/report.rst", "w") as rst_file:
rst_file.write(document)
try:
run(["rst2pdf", temp_dir + "/report.rst", "-s", "rst2pdf_stylsheet.style", "--use-floating-images", "-o", output_file], check=True)
run(["rst2pdf", temp_dir + "/report.rst", "-s", "rst2pdf_stylsheet.style", "-o", output_file], check=True)
rmtree(temp_dir)
return True
except CalledProcessError: