<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Bash on 闻道录</title>
    <link>https://blog.zjuyk.site/tags/bash/</link>
    <description>Recent content in Bash on 闻道录</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Thu, 06 Jul 2023 12:45:33 +0800</lastBuildDate><atom:link href="https://blog.zjuyk.site/tags/bash/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Bash 小技巧</title>
      <link>https://blog.zjuyk.site/notes/bash/</link>
      <pubDate>Thu, 06 Jul 2023 12:45:33 +0800</pubDate>
      
      <guid>https://blog.zjuyk.site/notes/bash/</guid>
      <description>
&lt;h3 id=&#34;四则运算&#34; class=&#34;header-anchor-wrapper&#34;&gt;四则运算
  &lt;a href=&#34;#%e5%9b%9b%e5%88%99%e8%bf%90%e7%ae%97&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;使用 &lt;code&gt;$(())&lt;/code&gt; 来计算，注意涉及到不同进制的四则运算可以这样&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;# 5+0xa+0b1010
echo $((5+16#a+2#1010))
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;判断参数是否为空&#34; class=&#34;header-anchor-wrapper&#34;&gt;判断参数是否为空
  &lt;a href=&#34;#%e5%88%a4%e6%96%ad%e5%8f%82%e6%95%b0%e6%98%af%e5%90%a6%e4%b8%ba%e7%a9%ba&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;if [ -z &amp;quot;$1&amp;quot; ] &amp;amp;&amp;amp; [ -z &amp;quot;$2&amp;quot; ]; then
    echo &amp;quot;Usage: $0 &amp;lt;parameter1&amp;gt; &amp;lt;parameter2&amp;gt;&amp;quot;
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;生成数字列表&#34; class=&#34;header-anchor-wrapper&#34;&gt;生成数字列表
  &lt;a href=&#34;#%e7%94%9f%e6%88%90%e6%95%b0%e5%ad%97%e5%88%97%e8%a1%a8&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;注意终点的数字是包含的&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;for i in $(seq 1 $END); do echo $i; done
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;判断文件不存在&#34; class=&#34;header-anchor-wrapper&#34;&gt;判断文件不存在
  &lt;a href=&#34;#%e5%88%a4%e6%96%ad%e6%96%87%e4%bb%b6%e4%b8%8d%e5%ad%98%e5%9c%a8&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;注意这里 &lt;code&gt;]&lt;/code&gt; 前面的空格是不能省略的&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;if [ ! -f &amp;quot;somefile&amp;quot; ]; then
    curl ...
fi
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
    <item>
      <title>对剪切板图片添加额外效果</title>
      <link>https://blog.zjuyk.site/posts/clipboard-image-customize/</link>
      <pubDate>Mon, 02 Aug 2021 18:14:06 +0800</pubDate>
      
      <guid>https://blog.zjuyk.site/posts/clipboard-image-customize/</guid>
      <description>&lt;p&gt;一直觉得 mac 的截图效果非常好看，之前在 ArchLinux 上用 imagemagick 撸了一个类似的，最近在体验 windows 11，顺便也移植了一份。&lt;/p&gt;
&lt;h3 id=&#34;1-实现效果&#34; class=&#34;header-anchor-wrapper&#34;&gt;1 实现效果
  &lt;a href=&#34;#1-%e5%ae%9e%e7%8e%b0%e6%95%88%e6%9e%9c&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;添加阴影&lt;/li&gt;
&lt;li&gt;添加圆角&lt;/li&gt;
&lt;li&gt;添加水印&lt;/li&gt;
&lt;li&gt;添加边框&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;2-实现流程&#34; class=&#34;header-anchor-wrapper&#34;&gt;2 实现流程
  &lt;a href=&#34;#2-%e5%ae%9e%e7%8e%b0%e6%b5%81%e7%a8%8b&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;


&lt;h4 id=&#34;21-剪切板操作&#34; class=&#34;header-anchor-wrapper&#34;&gt;2.1 剪切板操作
  &lt;a href=&#34;#21-%e5%89%aa%e5%88%87%e6%9d%bf%e6%93%8d%e4%bd%9c&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;想要对剪切板图片进行修改首先就要能获取剪切板的图片和向剪切板发送图片，在运行 Xorg 的 Linux 上可以很方便地使用 xclip 来操作&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;# get image from clipboard
xclip -selection clipboard -t image/png -o &amp;gt; /tmp/src.webp
# send image to clipboard
xclip -selection clipboard -t image/png -i /tmp/des.webp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但在 windows 11 上该如何获取呢？我先是查询了 powershell 的相关 API，然后我发现有现成的 Get-Clipboard 和 Set-Clipboard 两个模块函数可用&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-powershell&#34;&gt;# get image from clipboard
$img = Get-Clipboard -Format Image
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但很可惜我发现 &lt;code&gt;Get-Content path/to/file | Set-Clipboard&lt;/code&gt; 对文本是可以的，但是对图片却会乱码，在网上查询也没找到相关解释，于是我换了一种设置剪切板的方法&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-powershell&#34;&gt;# send result to clipboard
Add-Type -Assembly System.Windows.Forms
Add-Type -Assembly System.Drawing

$img = [Drawing.Image]::FromFile($result_image)
[Windows.Forms.Clipboard]::SetImage($img)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我也查询了一下 python 基于 PIL 和 win32clipboard 的操作方法&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;from PIL import ImageGrab
from io import BytesIO
import win32clipboard

# get image from clipboard
image = ImageGrab.grabclipboard()

# send image to clipboard
output = BytesIO()
border_image.convert(&#39;RGB&#39;).save(output, &#39;BMP&#39;)
data = output.getvalue()[14:]
output.close()

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
win32clipboard.CloseClipboard()
&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&#34;22-图片处理&#34; class=&#34;header-anchor-wrapper&#34;&gt;2.2 图片处理
  &lt;a href=&#34;#22-%e5%9b%be%e7%89%87%e5%a4%84%e7%90%86&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h4&gt;


&lt;h5 id=&#34;221-imagemagick&#34; class=&#34;header-anchor-wrapper&#34;&gt;2.2.1 imagemagick
  &lt;a href=&#34;#221-imagemagick&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h5&gt;

&lt;p&gt;对于图片的处理首先想到的就是 imagemagick 这个工具了，在 Linux 使用非常简单&lt;/p&gt;
&lt;p&gt;先加圆角，我这里使用的圆角弧度为 8&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;convert /tmp/src.webp \
	  \( +clone -alpha extract \
	  -draw &#39;fill black polygon 0,0 0,8 8,0 fill white circle 8,8 8,0&#39; \
	  \( +clone -flip \) -compose Multiply -composite \
	  \( +clone -flop \) -compose Multiply -composite \
    \) -alpha off -compose CopyOpacity -composite /tmp/output.webp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;再加阴影和边框，我设置的边框为 20px，这是为了配合我的水印图片&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;convert /tmp/output.webp -bordercolor none -border 20 \( +clone -background black -shadow 100x15+0+0 \) \
	+swap -background transparent -layers merge +repage /tmp/des.webp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;再加上自己的水印&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;composite -gravity SouthEast ~/.local/bin/watermark.webp /tmp/des.webp /tmp/des.webp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但我在 powershell 上尝试使用 imagemagick 的时候发现参数识别出现了问题，+clone 没认出来，还好 win 11 窗口自带阴影和圆角，那我只要打一下水印就好了&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-powershell&#34;&gt;$cmd = &amp;quot;composite -gravity SouthEast $watermark $source_image $result_image&amp;quot;
Invoke-Expression $cmd
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;在 scoop 安装 imagemagick 的时候我发现还引入了 ffmpeg 这个依赖包，我虽然也经常用它，但毕竟还是有点大，于是我尝试用 PIL 来处理图片。&lt;/p&gt;
&lt;p&gt;先加一下边框，我是 nord 配色的忠实用户，所以选用了 &amp;ldquo;#2E3440&amp;rdquo; 同时也是我桌面壁纸的主要颜色，这是我用 k-means 算法写的一个提取图片主要颜色的&lt;a href=&#34;https://gist.github.com/zjuyk/92f1c3776be2c87e06b34e5ba5151ada&#34;&gt;脚本&lt;/a&gt;。&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# add border
border = 20 # border size
border_color = &amp;quot;#2E3440&amp;quot; # border color

border_image = Image.new(&amp;quot;RGBA&amp;quot;, (image.width + border, image.height + border), border_color)
align = int(border / 2)
border_image.paste(image, (align, align))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;然后添加水印&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# add watermark
watermark = Image.open(r&amp;quot;C:\Users\zjuyk\Desktop\watermark.webp&amp;quot;)
watermark = watermark.convert(&amp;quot;RGBA&amp;quot;)
border_image.paste(watermark, (border_image.width - watermark.width, border_image.height - watermark.height), watermark)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;在尝试添加圆角的时候我发现，锯齿非常严重，严重影响美观度，所以没有放进脚本里，阴影也是一样，我打算全用 windows 11 自带的窗口阴影和圆角。如果非要自己实现的话，我建议准备几张 &lt;code&gt;mask image&lt;/code&gt; 来做图片遮罩。&lt;/p&gt;

&lt;h3 id=&#34;3-实现效果&#34; class=&#34;header-anchor-wrapper&#34;&gt;3 实现效果
  &lt;a href=&#34;#3-%e5%ae%9e%e7%8e%b0%e6%95%88%e6%9e%9c&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;imagemagick - Linux&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=&#34;Linux 实现&#34; src=&#34;https://blog.zjuyk.site/posts/clipboard-image-customize/addshadow.webp&#34;&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;#!/bin/bash -e

# Get the picture from flameshot
flameshot gui -r &amp;gt; /tmp/src.webp 
wait $!

# Get the picture from scrot
# scrot --select &amp;quot;/tmp/src.webp&amp;quot; 
# wait $!

# xclip -selection clipboard -t image/png -o &amp;gt; /tmp/src.webp

# add shadow, round corner, border and watermark
convert /tmp/src.webp \
	  \( +clone -alpha extract \
	  -draw &#39;fill black polygon 0,0 0,8 8,0 fill white circle 8,8 8,0&#39; \
	  \( +clone -flip \) -compose Multiply -composite \
	  \( +clone -flop \) -compose Multiply -composite \
    \) -alpha off -compose CopyOpacity -composite /tmp/output.webp

convert /tmp/output.webp -bordercolor none -border 20 \( +clone -background black -shadow 100x15+0+0 \) \
	+swap -background transparent -layers merge +repage /tmp/des.webp

composite -gravity SouthEast ~/.local/bin/watermark.webp /tmp/des.webp /tmp/des.webp

# Send the picture to clipboard
xclip -selection clipboard -t image/png -i /tmp/des.webp

# remove the left pictures
rm /tmp/src.webp /tmp/des.webp /tmp/output.webp
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;imagemagick - PowerShell&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=&#34;PowerShell 实现&#34; src=&#34;https://blog.zjuyk.site/posts/clipboard-image-customize/addwatermark.webp&#34;&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-powershell&#34;&gt;# Please add execution policy
# Set-ExecutionPolicy Unrestricted

# get image from clipboard
$img = Get-Clipboard -Format Image
if ($img -eq $null) {
        Write-Host &amp;quot;Clipboard contains no image.&amp;quot;
        Exit
}

# save it to desktop
$img.Save(&amp;quot;C:\Users\zjuyk\Desktop\src.webp&amp;quot;)

# add watermark
$watermark = &amp;quot;C:\Users\zjuyk\Desktop\watermark.webp&amp;quot;
$source_image = &amp;quot;C:\Users\zjuyk\Desktop\src.webp&amp;quot;
$result_image = &amp;quot;C:\Users\zjuyk\Desktop\res.webp&amp;quot;

$cmd = &amp;quot;composite -gravity SouthEast $watermark $source_image $result_image&amp;quot;
Invoke-Expression $cmd

# send result to clipboard
Add-Type -Assembly System.Windows.Forms
Add-Type -Assembly System.Drawing

$img = [Drawing.Image]::FromFile($result_image)
[Windows.Forms.Clipboard]::SetImage($img)

# remove temp files (do it manually)
Remove-Item &amp;quot;C:\Users\zjuyk\Desktop\src.webp&amp;quot; -Force
# Remove-Item &amp;quot;C:\Users\zjuyk\Desktop\res.webp&amp;quot; -Force
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;PIL - Python&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=&#34;Python 实现&#34; src=&#34;https://blog.zjuyk.site/posts/clipboard-image-customize/addborder.webp&#34;&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;from PIL import ImageGrab, Image
from io import BytesIO
import win32clipboard

if __name__ == &amp;quot;__main__&amp;quot;:
    # get image from clipboard
    image = ImageGrab.grabclipboard()

    # add border
    border = 20 # border size
    border_color = &amp;quot;#2E3440&amp;quot; # border color

    border_image = Image.new(&amp;quot;RGBA&amp;quot;, (image.width + border, image.height + border), border_color)
    align = int(border / 2)
    border_image.paste(image, (align, align))

    # add watermark
    watermark = Image.open(r&amp;quot;C:\Users\zjuyk\Desktop\watermark.webp&amp;quot;)
    watermark = watermark.convert(&amp;quot;RGBA&amp;quot;)
    border_image.paste(watermark, (border_image.width - watermark.width, border_image.height - watermark.height), watermark)

    # send image to clipboard
    output = BytesIO()
    border_image.convert(&#39;RGB&#39;).save(output, &#39;BMP&#39;)
    data = output.getvalue()[14:]
    output.close()

    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
    win32clipboard.CloseClipboard()
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;4-参考&#34; class=&#34;header-anchor-wrapper&#34;&gt;4 参考
  &lt;a href=&#34;#4-%e5%8f%82%e8%80%83&#34; class=&#34;header-anchor-link&#34;&gt;
    &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34;&gt;
&lt;svg
    xmlns=&#34;http://www.w3.org/2000/svg&#34;
    width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34;
    stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34; stroke-linecap=&#34;round&#34;
    stroke-linejoin=&#34;round&#34;&gt;
    &lt;line x1=&#34;4&#34; y1=&#34;9&#34; x2=&#34;20&#34; y2=&#34;9&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;4&#34; y1=&#34;15&#34; x2=&#34;20&#34; y2=&#34;15&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;10&#34; y1=&#34;3&#34; x2=&#34;8&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;&lt;line x1=&#34;16&#34; y1=&#34;3&#34; x2=&#34;14&#34; y2=&#34;21&#34;&gt;&lt;/line&gt;
&lt;/svg&gt;

&lt;/svg&gt;
  &lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-clipboard?view=powershell-7.1&#34;&gt;PowerShell API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://timgolden.me.uk/pywin32-docs/win32clipboard.html&#34;&gt;win32clipboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://imagemagick.org/script/command-line-processing.php&#34;&gt;Imagemagick&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://pillow.readthedocs.io/en/stable/&#34;&gt;PIL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
  </channel>
</rss>
