ObeoNetwork / M2Doc

The M2Doc technology enables the generation of Office Open XML documents from models.
http://obeonetwork.github.io/M2Doc/
Eclipse Public License 2.0
39 stars 22 forks source link

Converting images using "asImage()" methods (from one format to another) #468

Closed tbrouard closed 2 months ago

tbrouard commented 2 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[X] Support request => Please have a look to the support pages of our website : http://m2doc.org/support/

Current behavior

Using the method "asImage()" of the M2doc ImageServices.java class to export images in my word doesn't seem to be converting the format as described in the example provided in the documentation of the method. I watch the method call using the debug view and watch the values of the different parameter. The behavior appears to be the following :

The image is exported but the extension, therefore its format, is never changed. The type parameter is just stored in the attribut of the MImageImpl class.

image

Expected behavior

From what I understood of the documentation of the method it should change the format of the image from the original to the expected one. (From line 79 to 93 of the ImageServices.java class)

    // @formatter:off
    @Documentation(
        value = "Convert a String representing an URI to an Image and serialize it in the given format.",
        params = {
            @Param(name = "uri", value = "The Image uri, it can be relative to the template"),
        },
        result = "insert the image",
        examples = {
            @Example(expression = "'image.png'.asImage('jpg')", result = "insert the image 'image.jpg'"),
        }
    )
    // @formatter:on
    public MImage asImage(String uriStr, String type) {
        return asImage(uriStr, PictureType.valueOf(type.toUpperCase()));
    }

Minimal reproduction of the problem with instructions

I used in my word template this line : {m: 'name_of_my diagram_picture.png'.asImage('jpg')} Then looked at the format of the image put in my generated word : it's still '.png'

What is the motivation / use case for changing the behavior?

I would be interested in changing my images format into 'EMF' format since it is in the list of format that might be available in the PitcureType.java class. I would be also keen on information about how image exporting methods work as i might not have well understand them. Thanks

Environment


M2Doc version: 3.2.0
Capella version: 5.1.0
Platform version: Windows 10

Others:

ylussaud commented 2 years ago

The type passed to the asImage() service is used to tell M2Doc the format of the image if it can't be computed from the file extension. It's not used to convert the image format. To do that, you can create a Java service and use javax.imageio.ImageIO for instance.

And Yes the documentation is wrong...