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

feature: read/write transparency (alpha) property on fills #62

Open
scanny opened this issue Dec 6, 2013 · 3 comments
Open

feature: read/write transparency (alpha) property on fills #62

scanny opened this issue Dec 6, 2013 · 3 comments
Assignees
Milestone

Comments

@scanny
Copy link
Owner

scanny commented Dec 6, 2013

No description provided.

@ghost ghost assigned scanny Dec 6, 2013
@scanny scanny modified the milestones: v0.4.0, later Nov 16, 2014
@liuming
Copy link

liuming commented Mar 25, 2017

Hi @scanny I wonder what it takes to support this feature. I'd like to help and possibility provide a PR if you can point me a direction.

@scanny
Copy link
Owner Author

scanny commented Mar 25, 2017

Probably the easiest place to start is to create a single slide presentation having a single shape on it, then set the transparency, save, and inspect the XML. You should find an <a:alpha> element in the shape XML and that "specimen" will give most of the initial information needed.

There is some preliminary analysis here: http://python-pptx.readthedocs.io/en/latest/dev/analysis/dml-fill.html and here: http://python-pptx.readthedocs.io/en/latest/dev/analysis/dml-color.html

It looks like the MS API has a .Transparency property on FillFormat, so that's a pretty solid indication that's where we should do it too: https://github.com/scanny/python-pptx/blob/master/pptx/dml/fill.py#L20

opc-diag is handy for inspecting the XML. http://opc-diag.readthedocs.io/en/latest/

Why don't you have a look at these items and then you can ask any more specific questions you have :)

@keithcsqueensu
Copy link

keithcsqueensu commented Jul 9, 2022

Transparency options from PowerPoint's Format Shape GUI

The Format Shape pane contains the following Fill strategies.

In this comment, I will explore each of the Fill strategies and see how transparency works for each.

1. Solid Fill

  1. Create a new pptx file with a blank slide.
  2. Set slide layout to Blank
  3. Insert a rectangle on the slide. This results to the file before.pptx.
  4. I've set the transparency of that rectangle to 55%, resulting to the file solidFillTrans.pptx with the following modifications:
--- before/ppt/slides/slide1.xml

+++ solidFillTrans/ppt/slides/slide1.xml

@@ -39,6 +39,11 @@

           <a:prstGeom prst="rect">
             <a:avLst/>
           </a:prstGeom>
+          <a:solidFill>
+            <a:schemeClr val="accent1">
+              <a:alpha val="45000"/>
+            </a:schemeClr>
+          </a:solidFill>
         </p:spPr>
         <p:style>
           <a:lnRef idx="2">

The above is the Scheme Color only. I've created solidFillTransYellow.pptx with yellow color:

--- before/ppt/slides/slide1.xml

+++ solidFillTransYellow/ppt/slides/slide1.xml

@@ -39,6 +39,11 @@

           <a:prstGeom prst="rect">
             <a:avLst/>
           </a:prstGeom>
+          <a:solidFill>
+            <a:srgbClr val="FFFF00">
+              <a:alpha val="45000"/>
+            </a:srgbClr>
+          </a:solidFill>
         </p:spPr>
         <p:style>
           <a:lnRef idx="2">

2. No Fill

  1. Start from before.pptx, change fill of rectangle to NoFill, resulting to the file noFillOrig.pptx with the following modifications:
--- before/ppt/slides/slide1.xml

+++ noFillOrig/ppt/slides/slide1.xml

@@ -39,6 +39,7 @@

           <a:prstGeom prst="rect">
             <a:avLst/>
           </a:prstGeom>
+          <a:noFill/>
         </p:spPr>
         <p:style>
           <a:lnRef idx="2">
  1. There's no GUI option to change transparency.

3. Gradient Fill

  1. Start from before.pptx, change fill to Gradient, resulting to gradFillOrig.pptx:
--- before/ppt/slides/slide1.xml

+++ gradFillOrig/ppt/slides/slide1.xml

@@ -39,6 +39,35 @@

           <a:prstGeom prst="rect">
             <a:avLst/>
           </a:prstGeom>
+          <a:gradFill>
+            <a:gsLst>
+              <a:gs pos="0">
+                <a:schemeClr val="accent1">
+                  <a:lumMod val="5000"/>
+                  <a:lumOff val="95000"/>
+                </a:schemeClr>
+              </a:gs>
+            
  <a:gs pos="74000">
+                <a:schemeClr val="accent1">
+                  <a:lumMod val="45000"/>
+                  <a:lumOff val="55000"/>
+                </a:schemeClr>
+              </a:gs>
+              <a:gs pos="83000">
+                <a:schemeClr val="accent1">
+                 
 <a:lumMod val="45000"/>
+                  <a:lumOff val="55000"/>
+                </a:schemeClr>
+              </a:gs>
+              <a:gs pos="100000">
+                <a:schemeClr val="accent1">
+                  <a:lumMod val="30000"/>
+                  <a:lumOff val="70000"/>
+              
  </a:schemeClr>
+              </a:gs>
+            </a:gsLst>
+            <a:lin ang="5400000" scaled="1"/>
+          </a:gradFill>
         </p:spPr>
         <p:style>
           <a:lnRef idx="2">
  1. Add 44% transparency to Gradient Step 0, resulting to gradFillTrans.pptx:
--- gradFillOrig/ppt/slides/slide1.xml

+++ gradFillTrans/ppt/slides/slide1.xml

@@ -45,6 +45,7 @@

                 <a:schemeClr val="accent1">
                   <a:lumMod val="5000"/>
                   <a:lumOff val="95000"/>
+                  <a:alpha val="56000"/>
                 </a:schemeClr>
               </a:gs>
               <a:gs pos="74000">

4. Blip Fill

  1. Start from before.pptx, change fill to Picture / Texture Fill. Turn off "Tile picture as texture" and "Rotate with Shape". Resulting to blipFillOrig.pptx:
--- before/ppt/slides/slide1.xml

+++ blipFillOrig/ppt/slides/slide1.xml

@@ -39,6 +39,13 @@

           <a:prstGeom prst="rect">
             <a:avLst/>
           </a:prstGeom>
+          <a:blipFill dpi="0" rotWithShape="0">
+            <a:blip r:embed="rId2"/>
+            <a:srcRect/>
+            <a:stretch>
+              <a:fillRect/>
+            </a:stretch>
+          </a:blipFill>
         </p:spPr>
         <p:style>
           <a:lnRef idx="2">
  1. Add 55% transparency, resulting to blipFillTrans.pptx:
--- blipFillOrig/ppt/slides/slide1.xml

+++ blipFillTrans/ppt/slides/slide1.xml

@@ -40,7 +40,9 @@

             <a:avLst/>
           </a:prstGeom>
           <a:blipFill dpi="0" rotWithShape="0">
-            <a:blip r:embed="rId2"/>
+            <a:blip r:embed="rId2">
+              <a:alphaModFix amt="45000"/>
+            </a:blip>
             <a:srcRect/>
             <a:stretch>
               <a:fillRect/>

5. Pattern Fill

  1. Start from before.pptx, change fill to Pattern Fill, resulting to pattnFillOrig.pptx:
--- before/ppt/slides/slide1.xml

+++ pattnFillOrig/ppt/slides/slide1.xml

@@ -39,6 +39,14 @@

           <a:prstGeom prst="rect">
             <a:avLst/>
           </a:prstGeom>
+          <a:pattFill prst="pct5">
+            <a:fgClr>
+              <a:schemeClr val="accent1"/>
+            </a:fgClr>
+            <a:bgClr>
+              <a:schemeClr val="bg1"/>
+            </a:bgClr>
+          </a:pattFill>
         </p:spPr>
         <p:style>
           <a:lnRef idx="2">
  1. No transparency option is available in the GUI.

6. Background Fill

  1. Start from before.pptx, change fill to Background Fill, resulting to bkgFillOrig.pptx:
--- before/ppt/slides/slide1.xml

+++ bkgFillOrig/ppt/slides/slide1.xml

@@ -19,7 +19,7 @@

           <a:chExt cx="0" cy="0"/>
         </a:xfrm>
       </p:grpSpPr>
-      <p:sp>
+      <p:sp useBgFill="1">
         <p:nvSpPr>
           <p:cNvPr id="4" name="Rectangle 3">
             <a:extLst>
  1. No transparency option is available in the GUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants