dxfjs / writer

A JavaScript dxf generator written in TypeScript.
https://dxf.vercel.app
MIT License
83 stars 17 forks source link

Dxf Image dimensions issue #36

Open Magorick opened 1 year ago

Magorick commented 1 year ago

Hi,

I am trying to add images to dxf with different dimensions, setting different width and height. I found out that if I set smaller values to width and height, the images get bigger.

code example:

const dxf = new DxfWriter();

//IMAGE 1 const img1 = dxf.addImage( 'C:\Users\dev\Desktop\example.jpg', //Or the absolute path if not in the same folder. 'TEST', //The name of the image. point3d(10, 10, 0), // The insertion point. 600, // The width of the image in pixels. 600, //The height of the image in pixels. 1, //The scale to be applied to the image. 0 //The rotation angle (Degrees) to be applied to the image. ); img1.clippingStateFlag = 0;

//IMAGE 2 const img2 = dxf.addImage( 'C:\Users\dev\Desktop\example.jpg', //Or the absolute path if not in the same folder. 'TEST', //The name of the image. point3d(-10, -10, 0), // The insertion point. 60, // The width of the image in pixels. 60, //The height of the image in pixels. 1, //The scale to be applied to the image. 0 //The rotation angle (Degrees) to be applied to the image. ); img2.clippingStateFlag = 0;

const dxfString = dxf.stringify(); this.downloadFile(dxfString);


In the output dxf file, "IMAGE 2" (width 60 , height 60) is TEN times bigger than "IMAGE 1" (width 600 , height 600) and I was expecting the opposite result.

image

Maybe am I missing something?

tarikjabiri commented 1 year ago

Hi,

Really I have no idea why this work like that, but the width and height should be the acual width and height of the image in pixels, and you can control the size by the scale property.

But I will investigate when I have some time.

Regards

divya-shiv-pandey commented 1 year ago

You can do a custom scaling for the Image like shown below. It only works for square Images... this.dxf.addImage( Image Path Here, // Or the absolute path of the image if it isn't in the same folder. Random Name, point, // Insertion point of the bottomLeft corner of the image. width, // the width of the image height, // the height of the image (width * width) / 1024, // Scale 0, // rotation );