GithubHelp home page GithubHelp logo

xiebruce / php-get-image-from-clipboard Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 1.0 24 KB

Get image from clipboard and save it to an image file(jpg/png) by using php.

License: MIT License

PHP 87.08% PowerShell 12.92%

php-get-image-from-clipboard's Introduction

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.

php-get-image-from-clipboard's People

Contributors

xiebruce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

asvvvad1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.