<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>图床 &#8211; ChaBug安全</title>
	<atom:link href="/tags/%E5%9B%BE%E5%BA%8A/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Tue, 30 Jul 2019 01:59:52 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.5</generator>
	<item>
		<title>使用powershell导出剪切板图片</title>
		<link>/tools/681.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Tue, 30 Jul 2019 01:51:16 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[编程学习]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[图床]]></category>
		<guid isPermaLink="false">/?p=681</guid>

					<description><![CDATA[怎么导出QQ截图的图片到指定位置呢？powershell来帮你 我是一个喜欢记笔记写文章的菜鸡，而使用markdown记笔记最蛋疼的就是图片的存储问题，刚开始使用的是PicGo，可...]]></description>
										<content:encoded><![CDATA[<p>怎么导出QQ截图的图片到指定位置呢？<span class="wpcom_tag_link"><a href="/tags/powershell" title="powershell" target="_blank">powershell</a></span>来帮你</p>
<p>我是一个喜欢记笔记写文章的菜鸡，而使用markdown记笔记最蛋疼的就是图片的存储问题，刚开始使用的是<a href="https://github.com/Molunerfinn/PicGo">PicGo</a>，可以直接截图然后粘贴就是markdown的图片语法，但是使用的是第三方的<span class="wpcom_tag_link"><a href="/tags/%e5%9b%be%e5%ba%8a" title="图床" target="_blank">图床</a></span>。</p>
<p>而我自己原来用第三方图床也就是新浪的图床，后来新浪一波防盗链把我搞得<del>骂骂咧咧</del>措手不及，想了想，图片还是掌握在自己手中比较好，于是就有了本文。</p>
<h1>借助PicGo搞插件？</h1>
<p>刚好自己搭了一个图床http://static.chabug.org/ ，想着参考PicGo的思路，自己写一个插件，然后实现截图 快捷键 粘贴 一套操作，岂不是美滋滋？后来看到了PicGo需要装nodejs才能用插件，再想想nodejs的依赖和蛇皮语法，直接实力劝退，不了了之。</p>
<h1><span class="wpcom_tag_link"><a href="/tags/python" title="python" target="_blank">python</a></span>自己造轮子</h1>
<p>国光师傅写过一篇<a href="https://www.sqlsec.com/2018/06/img.html">Python 编写一个免费简单的图床上传工具二</a>，但是编写思路是采用<code>xclip</code>来操作<code>ubuntu</code>下的剪切板，而苦逼windows党不配这样操作。随卒。</p>
<h1>参考PicGo自己撸</h1>
<p>研究到这一步，实际上最关键的问题在于win下怎么去导出剪切板中的图片。百度谷歌了很多文章，发现都是牛头不照马尾，在此过程中我把PicGo作者的博客翻烂了，发现PicGo作者获取剪切板的图片采用的是命令行调用 https://github.com/PicGo/PicGo-Core/blob/dev/src/utils/clipboard/windows10.ps1 这个脚本。在第一行定义了最关键的项目https://github.com/octan3/img-clipboard-dump。这个就是我们想要的东西！</p>
<p>那么我们的问题就解决了！</p>
<p>看下<strong>dump-clipboard-png.ps1</strong></p>
<pre><code class="language-powershell ">Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()
if ($img -eq $null) {
    Write-Host "Clipboard contains no image."
    Exit
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$file = "{0}\clipboard-{1}.png" -f [Environment]::GetFolderPath('MyPictures'),((Get-Date -f s) -replace '[-T:]','')
Write-Host ("`n Found picture. {0}x{1} pixel. Saving to {2}`n" -f $img.PixelWidth, $img.PixelHeight, $file)

$stream = [IO.File]::Open($file, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb))
$encoder.Save($stream)
$stream.Dispose()

&amp; explorer.exe /select,$file
</code></pre>
<p>首先获取剪切板的图片，如果没图片就exit，然后新建一个位图对象，新建一个file变量当作文件名，从环境变量中拿到MyPictures的路径，然后写入图片。</p>
<p>相对我们想实现的效果还差一步就是直接向剪切板写入markdown格式的图片链接。我在这放出来我修改之后的脚本。(注意修改路径)</p>
<pre><code class="language-powershell ">Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()
if ($img -eq $null) {
    Write-Host "Clipboard contains no image."
    Exit
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$filename = ((Get-Date -f s) -replace '[-T:]','')
$file = "E:/work/myblog/static/img/uploads/{0}.png" -f $filename
Write-Host ("`n Found picture. {0}x{1} pixel. Saving to {2}`n" -f $img.PixelWidth, $img.PixelHeight, $file)

$stream = [IO.File]::Open($file, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb))
$encoder.Save($stream)
$stream.Dispose()

$str =  "![{0}](/img/uploads/{1}.png)" -f $filename,$filename
[Windows.Clipboard]::SetText($str)
</code></pre>
<p>然后把<code>dump-clipboard-png.cmd</code>改名为<code>png.cmd</code>和<code>png.ps1</code>放到环境变量里，截图，cmd运行<code>png</code>，那么你的剪切板就会写入一个markdown格式的图片咯。并且图片保存在了你的本地。</p>
<h1>进一步操作</h1>
<p>到现在我们基本的效果已经实现了，不过还是差一点，怎么去实现按下快捷键就导出图片到我们指定的位置呢？参考国光师傅的代码已经写的很清楚了。</p>
<p>https://github.com/sqlsec/imageMD/blob/master/imageMD.py</p>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>搞了一个图床</title>
		<link>/tools/662.html</link>
					<comments>/tools/662.html#comments</comments>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sun, 07 Jul 2019 09:54:38 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[图床]]></category>
		<guid isPermaLink="false">/?p=662</guid>

					<description><![CDATA[昨天把chabug弄炸了，然后图片有的也炸了… 今天看到之前用的很多的图片都是新浪图床的链接，自从新浪加上防盗链之后，博客的图片挂了一大波，之前也写过脚本来处理(这篇文章)，但是总...]]></description>
										<content:encoded><![CDATA[<p>昨天把chabug弄炸了，然后图片有的也炸了…</p>
<blockquote><p>今天看到之前用的很多的图片都是新浪<span class="wpcom_tag_link"><a href="/tags/%e5%9b%be%e5%ba%8a" title="图床" target="_blank">图床</a></span>的链接，自从新浪加上防盗链之后，博客的图片挂了一大波，之前也写过脚本来处理(<a href="https://y4er.com/post/downimg2local/">这篇文章</a>)，但是总不是很满意，因为图片现在是放到了GitHub，速度不行，然后在网上找了很多的图床，都不太稳，不然就是不太方便。然后我在GitHub上找到了一个好东西😁</p></blockquote>
<h2 id="auxpi"><i class="iconfont icon-link"></i>AUXPI</h2>
<p>Github：<a href="https://github.com/aimerforreimu/auxpi">AUXPI 集合多家 API 的新一代图床</a></p>
<p><a class="fancybox" href="https://y4er.com/img/uploads/20190707173858.png" data-fancybox="gallery" data-caption=""><img src="https://y4er.com/img/uploads/20190707173858.png" alt="" /></a></p>
<h2 id="功能特色"><i class="iconfont icon-link"></i>功能特色</h2>
<ul>
<li>支持 web 上传图片</li>
<li>支持 API 上传图片</li>
<li>支持分发，控制反转</li>
</ul>
<p>前台上传是不支持分发图片的。</p>
<p>后台中上传图片是支持分发的。</p>
<h2 id="分发原理"><i class="iconfont icon-link"></i>分发原理</h2>
<p><a class="fancybox" href="https://y4er.com/img/uploads/20190707173944.png" data-fancybox="gallery" data-caption=""><img src="https://y4er.com/img/uploads/20190707173944.png" alt="" /></a></p>
<h2 id="搭建好的成品"><i class="iconfont icon-link"></i>搭建好的成品</h2>
<p><a href="https://static.chabug.org/">https://static.chabug.org/</a></p>
<p>所有图片均存储在各大图床网站，<strong>本地不存储任何图片。</strong></p>
<p>欢迎使用🙂</p>
<p>有上传API哦，自行挖掘利用🤭</p>
]]></content:encoded>
					
					<wfw:commentRss>/tools/662.html/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
