Skip to content

Latest commit

 

History

History
82 lines (64 loc) · 2.93 KB

README.md

File metadata and controls

82 lines (64 loc) · 2.93 KB

php-get-image-from-clipboard

PHP-GetImgFromClipboard is a tool that allows you to get image on the clipboard(usually copy to the clipboard by taking a screenshot or copy from web page) and save it to an image file like jpg or png.

Install

composer require xiebruce/php-get-image-from-clipboard

Requires

Actually, php can not get image on the clipboard directly, so this tool is rely on other tools.

For macOS

For macOS, it relies on pngpaste, so you should install pngpaste first:

brew install pngpaste

For Windows 10

For Windows 10, it's free to use, nothing need to be install.

For Windows 7

For Windows 7, you need to update Powershell. Download Powershell update package "Win7AndW2K8R2-KB3191566-x64.zip" from here: https://www.microsoft.com/en-us/download/details.aspx?id=54616, then update and restart.

Before update, you can check the Powershell version. Click "Start" menu on the bottom right corner, input "powershell" to search, then powershell shows up like this: Xnip2019-09-05_14-43-33

Click to open it and type this command:

$PSVersionTable

Now you can see, before update, the Powershell version is 2.0: Check Powershell version before update

After update, the Powershell version is 5.0: Check Powershell version after update

For Linux Desktop

For Linux Desktop System(e.g. Ubuntu, Manjaro, CentOS etc.) , you need to install xclip.

On Ubuntu:

apt install xclip

I didn't test other Linux distributions, but it should be work as long as you install xclip.

Usage

<?php
	require 'vendor/autoload.php';
	
	use GetImgFromClipboard\GetImgFromClipboard;
	
	$obj = new GetImgFromClipboard();
	switch (PHP_OS){
		case 'Darwin':
			// For macOS, save screenshot to Desktop
			# /Users/youusername/Desktop/ScreenShot.jpg
			# /Users/youusername/Desktop/ScreenShot.jpg
			$savedImgPath = '/Users/bruce/Desktop/ScreenShot.jpg';
			break;
		case 'WINNT':
			// For Windows, save screenshot to Desktop
			# C:\Users\youusername\Desktop\ScreenShot.jpg
			# C:\Users\youusername\Desktop\ScreenShot.png
			$savedImgPath = 'C:\Users\youusername\Desktop\ScreenShot.png';
		case 'Linux':
			// For Linux, save screenshot to Desktop
			# /home/yourusername/Desktop/ScreenShot.jpg
			# /home/yourusername/Desktop/ScreenShot.png
			$savedImgPath = '/home/yourusername/Desktop/ScreenShot.jpg';
	}
	$savedImgPath = $obj->save($savedImgPath);
	echo $savedImgPath . "\n";

Acknowledgement

Thanks to octan3's img-clipboard-dump, I use it to get image from clipboard on Windows in my Project.