{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/2008/07/22/tweaking-png-transparency-with-imagemagick/","result":{"data":{"markdownRemark":{"html":"<p>This took me way too long to find out, so I thought I’d blog here and hopefully save someone else some time.</p>\n<p><a href=\"https://imagemagick.org/\">ImageMagick</a> is a great swiss-army-knife type tool, with a <a href=\"https://imagemagick.org/script/command-line-options.php\">shed-load of options</a> for converting and combining images. Unfortunately, the sheer number of options can make it a bit time-consuming and frustrating trying to find the one you want.</p>\n<p>My aim was simple: given a PNG, make the <em>whole thing</em> semi-transparent.</p>\n<p>Searching Google using “transparent” and “opacity” drew a blank - all I got was instructions on how to set transparency for certain <em>colours</em> - not what I wanted to do.</p>\n<p>The word I was missing was “alpha”, and the magic incantation for changing the opacity of the whole image is:</p>\n<pre class=\"grvsc-container default-dark\" data-language=\"bash\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"grvsc-source\"><span class=\"mtk1\">convert input.png -channel Alpha -evaluate Divide 2 output.png</span></span></span></code></pre>\n<p>In my case, I wanted to set the PNG to be 50% transparent (hence “Divide 2”.) Of course, you can change that number to whatever works for you.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    position: relative;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n    line-height: 1.4;\n  }\n  \n  .grvsc-code {\n    display: table;\n  }\n  \n  .grvsc-line {\n    display: table-row;\n    box-sizing: border-box;\n    width: 100%;\n    position: relative;\n  }\n  \n  .grvsc-line > * {\n    position: relative;\n  }\n  \n  .grvsc-gutter-pad {\n    display: table-cell;\n    padding-left: 0.75rem;\n    padding-left: calc(var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem)) / 2);\n  }\n  \n  .grvsc-gutter {\n    display: table-cell;\n    -webkit-user-select: none;\n    -moz-user-select: none;\n    user-select: none;\n  }\n  \n  .grvsc-gutter::before {\n    content: attr(data-content);\n  }\n  \n  .grvsc-source {\n    display: table-cell;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-source:empty::after {\n    content: ' ';\n    -webkit-user-select: none;\n    -moz-user-select: none;\n    user-select: none;\n  }\n  \n  .grvsc-gutter + .grvsc-source {\n    padding-left: 0.75rem;\n    padding-left: calc(var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem)) / 2);\n  }\n  \n  /* Line transformer styles */\n  \n  .grvsc-has-line-highlighting > .grvsc-code > .grvsc-line::before {\n    content: ' ';\n    position: absolute;\n    width: 100%;\n  }\n  \n  .grvsc-line-diff-add::before {\n    background-color: var(--grvsc-line-diff-add-background-color, rgba(0, 255, 60, 0.2));\n  }\n  \n  .grvsc-line-diff-del::before {\n    background-color: var(--grvsc-line-diff-del-background-color, rgba(255, 0, 20, 0.2));\n  }\n  \n  .grvsc-line-number {\n    padding: 0 2px;\n    text-align: right;\n    opacity: 0.7;\n  }\n  \n  .default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .default-dark .mtk1 { color: #D4D4D4; }\n  .default-dark .grvsc-line-highlighted::before {\n    background-color: var(--grvsc-line-highlighted-background-color, rgba(255, 255, 255, 0.1));\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, rgba(255, 255, 255, 0.5));\n  }\n</style>","timeToRead":1,"frontmatter":{"title":"Tweaking PNG transparency with ImageMagick","blurb":"A brief article with command-line example using ImageMagick to tweak an image’s transparency","date":"2008-07-22T12:21:32.000Z","modified":"2011-01-03T17:20:14.000Z"}}},"pageContext":{"slug":"/blog/2008/07/22/tweaking-png-transparency-with-imagemagick/","next":{"fields":{"slug":"/blog/2008/08/08/svn-log-message-encoding-problem/"},"frontmatter":{"title":"SVN log message encoding problem"}},"previous":{"fields":{"slug":"/blog/2008/07/21/microformats-dark-data-and-css-part-2/"},"frontmatter":{"title":"Microformats, dark data and CSS - part 2"}}}},"staticQueryHashes":["1192980692"]}