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

Image: Add transparency #1053

Merged
merged 1 commit into from
Mar 1, 2022
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
6 changes: 6 additions & 0 deletions src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ export interface ImageProps extends PositionProps, DataOrPathProps {
* @default false
*/
rounding?: boolean
/**
* Transparency (percent)
* - range: 0-100
* @default 0
*/
transparency?: number
/**
* Image sizing options
*/
Expand Down
1 change: 1 addition & 0 deletions src/gen-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ export function addImageDefinition(target: PresSlide, opt: ImageProps) {
rotate: opt.rotate || 0,
flipV: opt.flipV || false,
flipH: opt.flipH || false,
transparency: opt.transparency || 0,
}

// STEP 4: Add this image to this Slide Rels (rId/rels count spans all slides! Count all images to get next rId)
Expand Down
6 changes: 5 additions & 1 deletion src/gen-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ function slideObjectToXml(slide: PresSlide | SlideLayout): string {
let imageOpts = slideItemObj.options as ImageProps
let sizing = imageOpts.sizing,
rounding = imageOpts.rounding,
transparency = imageOpts.transparency,
width = cx,
height = cy

Expand All @@ -594,14 +595,17 @@ function slideObjectToXml(slide: PresSlide | SlideLayout): string {
(slide._relsMedia || []).filter(rel => rel.rId === slideItemObj.imageRid)[0]['extn'] === 'svg'
) {
strSlideXml += '<a:blip r:embed="rId' + (slideItemObj.imageRid - 1) + '">'
strSlideXml += ` <a:alphaModFix amt="${Math.round((100 - transparency) * 1000)}"/>`
strSlideXml += ' <a:extLst>'
strSlideXml += ' <a:ext uri="{96DAC541-7B7A-43D3-8B79-37D633B846F1}">'
strSlideXml += ' <asvg:svgBlip xmlns:asvg="http://schemas.microsoft.com/office/drawing/2016/SVG/main" r:embed="rId' + slideItemObj.imageRid + '"/>'
strSlideXml += ' </a:ext>'
strSlideXml += ' </a:extLst>'
strSlideXml += '</a:blip>'
} else {
strSlideXml += '<a:blip r:embed="rId' + slideItemObj.imageRid + '"/>'
strSlideXml += '<a:blip r:embed="rId' + slideItemObj.imageRid + '">'
strSlideXml += ` <a:alphaModFix amt="${Math.round((100 - transparency) * 1000)}"/>`
strSlideXml += '</a:blip>'
}
if (sizing && sizing.type) {
let boxW = sizing.w ? getSmartParseNumber(sizing.w, 'X', slide._presLayout) : cx,
Expand Down