Open .png image in Paint.Net from PHP script on Windows 10

Open .png image in Paint.Net from PHP script on Windows 10

tutorial open paint net image from php script

This tutorial will show you how to run paint.net image editing software from a php script. Paint.NET is image and photo editing software for PCs that run Windows. It features an intuitive and innovative user interface with support for layers, unlimited undo, special effects, and a wide variety of useful and powerful tools.

1. Install XAMPP with PHP for Windows

XAMPP is an easy to install free Apache distribution containing MariaDB, PHP and Perl. 

Goto official website, download and install it : 

https://www.apachefriends.org/index.html


2. Add PHP folder to Path Windows Environment Variable

In search bar type "env", click on "Edit the system environment variable" and "Open".


In "System properties" window click on "Environment Variables..." button in right bottom corner.
Than select "Path" environment variant and click "Edit" button.


Make sure path to PHP exists, if not - add it. For example on my computer :
C:\xampp\php

Save and close dialog windows.

3. Test PHP correct setup in Windows Command Prompt ( CMD)

Open Windows command prompt ( cmd ) 



Type following command and press Enter button on keyboard : 

php -version



4. Install Paint.Net for Windows

Download and install Pain.Net from afficial website.



5. Write PHP script to open image using Paint.Net protocol

Create file on Desktop. Name it automation.php.

Paste following code into php file :


<?php
   
    /**
     * Run script :
     *
     * CD C:\Users\Dev\Desktop
     * php automation.php
     */

    $MY_ANIME_IMAGE_PATH = "C:\Users\Dev\Desktop\Yumeko.png";

    openInPaintNet($MY_ANIME_IMAGE_PATH);

    function openInPaintNet( $pathToImage ){
        // Paint.Net protocol
        // https://www.getpaint.net/doc/latest/paintdotnetProtocol.html
        $cmd = "start paintdotnet:\"$pathToImage\"";
        exec($cmd);
    }

?>


Change path to your image !!!. I used Yumeko.png image on Desktop.


6. Run PHP script from Command Prompt ( CMD)

Open new window command prompt.

Type following command and press Enter ( change to your script path ! ):

CD C:\Users\Dev\Desktop

Type following command to run PHP script :

php automation.php

As result PHP should open Paint.Net with image you provided. 



No comments:

Post a Comment