Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add imageFit to drawImage method #332

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/doc_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ export interface IDocOptions {
compress?: boolean;

/**
* Specifies whether to apply the [`imageFit`](https://surveyjs.io/Documentation/Library?id=questionimagemodel#imageFit) property to exported [Image](https://surveyjs.io/Documentation/Library?id=questionimagemodel) questions.
* Specifies whether to apply `imageFit` settings specified in the survey JSON schema to exported images.
*
* Default value: `false`
*
* This property applies the following settings:
*
* - [`imageFit`](https://surveyjs.io/form-library/documentation/api-reference/add-image-to-survey#imageFit) to exported [Image](https://surveyjs.io/form-library/documentation/api-reference/add-image-to-survey) questions
* - [`imageFit`](https://surveyjs.io/form-library/documentation/api-reference/image-picker-question-model#imageFit) to exported [Image Picker](https://surveyjs.io/form-library/documentation/api-reference/image-picker-question-model) questions
* - [`logoFit`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#logoFit) to an exported logo in the survey header
*
* If you enable the `applyImageFit` property, the quality of images may be lower because they pass through several conversions. If `applyImageFit` is disabled, exported images fill the entire container and do not preserve their aspect ratio, but their quality remains the same because they are exported as is.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/event_handler/draw_canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ export interface IDrawImageOptions extends IDrawRectOptions {
* A string value with a base64-encoded image to be drawn.
*/
base64: string;
/**
* Specifies how to resize the image to fit it into its container.
*
* Default value: `"contain"` if [`applyImageFit`](https://surveyjs.io/pdf-generator/documentation/api-reference/idocoptions#applyImageFit) is enabled or `undefined` if not.
*
* Refer to the [`object-fit`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property description for information on accepted values.
*/
imageFit?: string;
}

/**
Expand Down Expand Up @@ -245,10 +253,12 @@ export class DrawCanvas {
height: imageOptions.height
};
const imageRect: IRect = this.alignRect(imageOptions, imageSize);
this.controller.pushMargins(0, 0);
this.packs.push(await SurveyHelper.createImageFlat(
SurveyHelper.createPoint(imageRect, true, true),
null, this.controller, { link: imageOptions.base64,
width: imageRect.xRight - imageRect.xLeft,
height: imageRect.yBot - imageRect.yTop }));
height: imageRect.yBot - imageRect.yTop, objectFit: imageOptions.imageFit }, !!imageOptions.imageFit || this.controller.applyImageFit));
this.controller.popMargins();
}
}
Loading