I have a PSD file with 3 layers. What I want to do is change the 3rd, deepest layer's image and save the whole PSD file as PNG.
Is this possible with python or the ubuntu command line?
I've already looked at psd tools but it's only good for exporting images as PNG in my case, I've looked at this blog post but not sure if it will allow me to change layer's image and where to find some documentation
If you really need Python, try to use photoshop-python-api
But even this not support all the functionalities of Photoshop.
Win32com API can give a vast range of functionalities but it's for windows.
Have you ever tried ExtendScript JS for Phothoshop? This is a built-in script editor for Adobe and a script listener is also available so you can easily make functions you need.
Scripting Guide
Scripting Listener
Related
For my bachelor thesis I have to convert DICOM data to a 3d model and import this into unity so I can create a virtual reality. So the data out of 3DSlicer has to be updated in Unity automatically. You can say I have to link the two programs. What do you think is the best way to do this? Should I create a Matlab or Python module or is there a better way?
I am sorry if there is already a similar question but I have searched for answers on the internet and unfortunately I couldn't find an answer.
I would really appreciate your help.
Since slicer is compatible to python codes. you can try to access to the unity codes, if you use ubuntu it is probably easier to use a shell script to call the unity functions you need withing the python codes of slicer.
I did it with ANSYS softwares to link two different softwares together and export an output from the first software and pass it to the second software.
Rather than this automatic way, this is a guideline about how to export data from other apps to Unity
https://docs.unity3d.com/Manual/HOWTO-exportFBX.html
I have a netcdf file that I would like to convert to an image (joed, png, gif) using a command line tool.
Is someone could please help me with the library name and possibly a link to how it is done.
Regards
David
Others have mentioned commercial solutions with ArcGIS, IDL and Matlab, but here's one way to do it using Python, using the netCDF4 module to read the netcdf file, and matplotlib to create the image. The netCDF4 module will read both NetCDF3, NetCDF4 files, and also read remote NetCDF (or other files) served via the OPeNDAP service. Below I read topography data using the OPeNDAP service, so you should be able to run the program without changes. The netCDF4 module can be a bit difficult to build, but it's included in the Python(x,y), Enthought Canopy and Continuum Anaconda distributions.
import matplotlib.pyplot as plt
import netCDF4
# open a local NetCDF file or remote OPeNDAP URL
url = 'http://www.ngdc.noaa.gov/thredds/dodsC/relief/ETOPO1/thredds/ETOPO1_Bed_g_gmt4.nc'
nc = netCDF4.Dataset(url)
# examine the variables
print nc.variables.keys()
print nc.variables['z']
# sample every 10th point of the 'z' variable
topo = nc.variables['z'][::10,::10]
# make image
plt.figure(figsize=(10,10))
plt.imshow(topo,origin='lower')
plt.title(nc.title)
plt.savefig('image.png', bbox_inches=0)
which produces this image:
Here is the official list of software for manipulating NetCDF.
http://www.unidata.ucar.edu/software/netcdf/software.html
If there is anything it is probably there. But I have a couple of comments on the subject if you are interested.
What platform are you using? Linux, Windows etc? Whatever the answer I think the answer is you will be struggling to find a command line tool with out creating it yourself.
It is probably relatively easy to create something using Java or Python and some GDAL libraries or the like. I have made something similar using ArcGIS if you have this but it is not command line because that is quite difficult to achieve.
Part of the problem you will face is that in using a command line you will need to have additional information as to how it is exported setup before hand but this information does not lend itself to a non-GUI environment.
Questions such as is it going to be grey scale or colour. If colour which colours because these will need to be defined. Say we use blue to red colour ramp then is red a high value or a low value. How is the colour going to be assigned to the values. Will it be gradual or will it be stepped e.g. values 0 - 10 correspond to a single colour then 10 - 20 to another colour.
It's not command line but 'NcView' may work for you.
http://meteora.ucsd.edu/~pierce/ncview_home_page.html
This can be done using my new package ncplot (available through pypi or conda-forge). It works as either a command line tool or in Python, and will generate interactive plots from the NetCDF files.
On the command line just do the following:
ncplot infile.nc
In Python (preferably in a Jupyter notebook). Just do the following:
from ncplot import ncplot
ncplot("infile.nc")
IDV is a good visualization tool for NetCDF, but, as far as I know, there is no command line interface.
I would recommend Matlab. It has read and write functions for NetCDF as well as an extensive plotting library...probably one of the best. You can then compile the matlab code and run it from the command line.
this may help:
http://gmt.soest.hawaii.edu/gmt/html/man/grdimage.html
here some examples:
web.ics.purdue.edu/~ecalais/teaching/gmt/GMT_6.pdf
GDAL can do this and you can control the output colour palettes in a variety of ways, and the rgdal package provides an R interface to some of this.
R has support to read NetCDF files and write to image files via a number of contributed packages, namely ncdf, RNetCDF and ncdf4.
If you want a commandline facility to enable to produce a simple plot without needing to do any coding there is
1. ncview
ncview file.nc
which can produce a ps plot with "print to file" but it is not very helpful as the colorbar legend is not included
2. Panoply
A second point and click method is to use
panoply
which is available here: https://www.giss.nasa.gov/tools/panoply/
3. CDO
The third method is to use CDO from the command line, (but make sure you have compiled it with MAGICS++ support included).
For example, you can make a simple PNG map of data in a netcdf file with the following command:
cdo shaded,device="png" in.nc plot
which will provide a file called "plot_variablename.png"
See the documentation here: https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial#Plotting
My wife recently started a business making soap bars and the soap labels have quickly spiraled out of control into tons of diverging Gimp .xcf files. The only difference between the files are the names of the product, description, and ingredients. I'd like to make a template and produce the labels from a .xcf file and maybe a .xml or .ini file that has the text data. I've been eyeing python-fu, but I'm not quite sure if it does what I'd like. I'd like to stick to python where possible because it's simple.
Are there facilities in python + gimp to do what I'd like? Could something similar be done in anything other than gimp?
Edit: Additionally, I have to make pages of stickers to print, so some means of optimizing the number of stickers that can fit on a page (2d bin pack?) would be a big plus.
The Python Imaging Library (PIL) can quite easily read in an image, put some text on it, and write it back out. Use the Image module to read and write, and the ImageDraw module to add the text.
I doubt that it can use the .xcf format though, you'll probably want to convert to .png.
You can script GIMP in Python, and pretty much everything you can do o n the prgoram can be done via the API -- you can check for the available API functions in help->procedure browser.
To enable Python scripting in gimp 2.6 under Windows, you have to google for it -- Python, python gtk and one other package have to be installed before GIMP.
Python's PIL is fine for simple images, but it is weak in arttistic pixel manipulation, which is available with GIMP.
I am searching for a way to write a simple python
program to perform an automatic edit on an audio file.
I wrote with PIL automatic picture resizing to a predefined size.
I would like to write the same for automatic file re-encoding into a predefined bitrate.
similarly, i would like to write a python program that can stretch an audio file and re-encode it.
do i have to parse MP3's by myself, or is there a library that can be used for this?
Rather than doing this natively in Python, I strongly recommend leaving the heavy lifting up to FFMPEG, by executing it from your script.
It can chop, encode, and decode just about anything you throw at it. You can find a list of common parameters here: http://howto-pages.org/ffmpeg/
This way, you can leave your Python program to figure out the logic of what you want to cut and where, and not spend a decade writing code to deal with all of the audio formats available.
If you don't like the idea of directly executing it, there is also a Python wrapper available for FFMPEG.
There is pydub. It's an easy to use library.
I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying to figure out a way I can, from a bash/perl/python/whatever-else program:
load the PSD
edit the text in said layer
flatten all layers in the image
save as a web-friendly format like PNG or JPG
I immediately thought of ImageMagick, but I don't think I can edit the text layer through IM. If I can accomplish the first two steps some other programmatic way, I can always use ImageMagick to perform the last two steps.
After a couple of hours of googling and searching CPAN and PyPI, I still have found nothing promising. Does anyone have advice or ideas on the subject?
If you don't like to use the officially supported AppleScript, JavaScript, or VBScript, then there is also the possibility to do it in Python. This is explained in the article Photoshop scripting with Python, which relies on Photoshop's COM interface.
I have not tried it, so in case it does not work for you:
If your text is preserved after conversion to SVG then you can simply replace it by whatever tool you like. Afterwards, convert it to PNG (eg. by inkscape --export-png=...).
The only way I can think of to automate the changing of text inside of a PSD would be to use a regex based substitution.
Create a very simple picture in Photoshop, perhaps a white background and a text layer, with the text being a known length.
Search the file for your text, and with a hex editor, search nearby for the length of the text (which may or may not be part of the file format).
Try changing the text, first to a string of the same length, then to something shorter/longer.
Open in Photoshop after each change to see if the file is corrupt.
This method, if viable, will only work if the layer in question contains a known string, which can be substituted for your other value. Note that I have no idea whether this will work, as I don't have Photoshop on this computer to try this method out. Perhaps you can make it work?
As for converting to png, I am at a loss. If the replacing script is in Python, you may be able to do it with the Python Imaging Library (PIL, which seems to support it), but otherwise you may just have to open Photoshop to do the conversion. Which means that it probably wouldn't be worth it to change the text pragmatically in the first place.
Have you considered opening and editing the image in The GIMP? It has very good PSD support, and can be scripted in several languages.
Which one you use depends in part on your platform, the Perl interface didn't work on Windows the last I knew. I believe Scheme is supported in all ports.
You can use Photoshop itself to do this with OLE. You will need to install Photoshop, of course. Win32::OLE in Perl or similar module in Python. See http://www.adobe.com/devnet/photoshop/pdfs/PhotoshopScriptingGuide.pdf
If you're going to automate Photoshop, you pretty much have to use Photoshop's own scripting systems. I don't think there's a way around that.
Looking at the problem a different way, can you export from Photoshop to some other format which supports layers, like PNG, which is editable by ImageMagick?
You can also try this using Node.js. I made a PSD command-line tool
One-line command install (needs NodeJS/NPM installed)
npm install -g psd-cli
You can then use it by typing in your terminal
psd myfile.psd -t
You can check out the code to use it from another node script or use it through your shell is from another Bash/Perl/whatever script.