Search code examples
pythonjsoneuro

How to change the image size of an Europass in JSON?


I did a program in Python which sends JSON data to the Europass web and gets from it a CV.

It's working great, but the image of the person is looking bad, because I send a square picture, and the Europass CV shows a rectangular image, so the people faces are looking too thin.

I wouldn't like to resize the image in Python, because theoretically the dimension of the picture can be modified in the JSON data:

Default value

"Photo" : {
  "MimeType" : "image/jpeg",
  "Data" : ... (base64 code) ...,
  "Metadata" : [ {
    "Key" : "dimension",
    "Value" : "591x608"
  }, {
    "Key" : "number-of-pages",
    "Value" : "1"
  } ]
}

My attempt:

"Photo" : {
  "MimeType" : "image/jpeg",
  "Data" : my_image,
  "Metadata" : [ {
    "Key" : "dimension",
    "Value" : "591x591"
  }, {
    "Key" : "number-of-pages",
    "Value" : "1"
  } ]
}

As you can see, I'm trying to print a square picture setting dimension to 591x591, but when I see the generated CV, the picture is rectangular (I guess its size is 591x608 again).

Can anyone help me, please?

Thank you in advance!


Solution

  • The dimension of the image can't be modified from the JSON. You must pass in the dictionary the picture with the right dimension (315x365) if you don't want the image to be deformed. You can modify the image through the library PIL of Python.

    You can see here what I did to adjust the image to the Europass dimension picture:

    How to resize an image an cut the excess area of it in Python?

    Hope it helps to anyone.