-->

Photoshop on web server for scripts

2019-04-16 16:14发布

问题:

So, I'm trying to think of the best way to solve a problem I have.

The problem is that I produce many websites for my job and as CSS3 and HTML5 introduce themselves powerful I want to eliminate almost all images from my websites. For button icons and various other things I have a sprite image with all the icons on that I just shift around depending what icon I need. What I need to be able to do is recolour this image dynamically on the web server so that I don't have to open up Photoshop and recolour the icons manually.

I have done some research and the only thing that I've come across that has a chance of working the way I want it to is a Photoshop JavaScript. My question is, once I've written my script and it recolours my icon image, can it be done on a server so, when a user clicks a button for example, the image is recoloured and saved to the server?

Would this require installing Photoshop being installed on the server? Is this even possible?

回答1:

Photoshop is just available for Mac or Windows as you will know.

As far as i know you can't install Photoshop on Windows Server. (I tried it with CS4 by myself - maybe it works with CS6 knowadays). But you could install PS on a Win 7 machine behind a firewall.

If you use a Windows machine you can use COM for automation. I tried it and it worked well.

I have done a similiar thing you are thinking of with two Macs and PS Javascript (Imagemagick, PIL etc. weren't working for me, because the job was too complicated) on a medium traffic webpage. So i don't agree with Michaels answer.

First thing: think about caching the images and use the low-traffic-time to compute images which could be needed in future. This really made things easier for me.

Second Thing: Experiment with image size, dpi etc. The smaller the images - the faster the process.

My Workflow was:

  • Webserver is writing to a database ("Hey i need a new image with name "path/bla.jpg").
  • A Ajax call is checking if the image is present. If not - show "processing your request placeholder"
  • A script running in a infinite loop on the mac behind a firewall is constanly checking if a new image is needed.
  • If it finds one it is updating the database ("Mac One will compute this job"). This prevents that every Mac will go for the new image.
  • The script is calling Photoshop. Photoshop is computing the image.
  • The script uploads the image (i used rsync) to the webserver.
  • ajax-call sees the new image and presents it to the user.
  • Script on the Mac updates database "image successfully created".

You will need some error handling logic etc.



回答2:

Uhm this problem has been bothering me for years too.. all i always wished was to have a Photoshop Server which i could talk trough an API and get things done.. well.. i have built something that is Closer... using the generator plugin i can connect thought a web-socket and inject javascript in Photoshop.. technically you are able to do anything that can be done using photoshop scripting guide.... (Including manipulating existing PDS)

This library https://github.com/Milewski/generator-exporter exports all the marked layers with a special syntax as its desired format... this code could run on the server.. using nodejs

import { Generator } from 'generator-exporter'
import * as glob from 'glob'
import * as path from 'path'

const files = glob.sync(
    path.resolve(__dirname, '**/*.psd')
);

const generator = new Generator(files, {
    password: '123456',
    generatorOptions: {
        'base-directory': path.resolve(__dirname, 'output')
    }
})


generator.start()
         .then(() => console.log('Here You Could Grab all the generated images and send back to client....'));

however i wouldn't recommend using this for heavy usage with too many concurrent tasks... because it needs photoshop installed locally... Photoshop GUI will be initialized.. this process is quite slow. so it doesn't really fit for a busy workflow.