Python Forum
Problem posting image to clipboard
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem posting image to clipboard
#1
I am running Windows 10 Version 10.0.18363 Build 18363.
Python 3.8.5
Apache 2.4.41

I found an example of how to copy an image to windows clipboard.
If I run the program at cmd.exe level, it works and I'm able to post the copied image from the clipboard.
If I execute the same program from within a PHP script using exec(program to run),
it runs without any errors. However the image is not in the clipboard.
I've tried creating a .bat file and then using PHP exec(.bat file), nothing is copied to the clipboard.
Again the .bat file when run at cmd.exe level, runs successfully.
I've run whoami at cmd.exe level and the correct user (ie myself as administrator) displays noellaptop\rorke
The code below my Python script.

#!c:/users/rorke/appdata/local/programs/python/python38/python.exe

from io import BytesIO
import win32clipboard
from PIL import Image
import cgi, cgitb 

print ("Content-type:text/html\r\n\r\n")

# Create instance of FieldStorage 
#form = cgi.FieldStorage() 
#filepath = form.getvalue('image_url')
filepath = "C:/wamp64/www/PhotoApp2.0/favicon.ico"
#print(filepath)

def send_to_clipboard(clip_type, data):
	win32clipboard.OpenClipboard()
	win32clipboard.EmptyClipboard()
	win32clipboard.SetClipboardData(clip_type, data)
	win32clipboard.CloseClipboard()
	print("Done!")

image = Image.open(filepath)
output = BytesIO()
image.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()

send_to_clipboard(win32clipboard.CF_DIB, data)
The code below is my PHP script.

<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<?php
$cmd = 'powershell C:/Users/rorke/AppData/Local/Programs/Python/Python38/python.exe
C:/wamp64/bin/apache/apache2.4.41/cgi-bin/hpCopyImage.py';

echo $cmd;
exec($cmd, $out, $ret);
print_r($out);
print_r($ret);
?>
</div>
</body>
</html>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem When using canny edge detection,black image returned rickyw2777 1 424 Feb-17-2025, 03:22 AM
Last Post: rickyw2777
  tkinter photo image problem jacksfrustration 5 3,356 Jun-27-2024, 12:06 AM
Last Post: AdamHensley
  non-latin characters in console from clipboard Johanson 3 1,556 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  Python loop for posting data to web marciokoko 10 3,327 Aug-26-2023, 02:17 AM
Last Post: deanhystad
  saving and loading text from the clipboard with python program MaartenRo 2 2,871 Jan-22-2022, 05:04 AM
Last Post: MaartenRo
  How to listen to clipboard content change without polling the clipboard continuously? edgelord 0 3,278 Nov-27-2020, 06:07 AM
Last Post: edgelord
  Problem loading an image dataset into Tensorflow MohammedSohail 1 2,285 Jun-09-2020, 02:09 PM
Last Post: nuffink
  How to copy data to clipboard OAP 10 14,575 Mar-19-2020, 10:32 PM
Last Post: OAP
  How can I paste an entire file from clipboard to a folder? daverave1212 5 11,667 Feb-08-2020, 04:33 PM
Last Post: snippsat
  cv2 problem when saving image majstr 7 7,612 Jan-21-2020, 05:39 PM
Last Post: majstr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020