is there any way to connect GIMP with PHP and use its libraries? It seems that all i do my development use linux as a production server example for resise image or croping
-
What kind of images? Do you really need gimp? Is this an XY problem? – PeeHaa Dec 29 '16 at 21:31
-
See https://www.gimp.org/tutorials/Basic_Batch/ for command line usage. ("with PHP" is not a useful search qualifier. You commonly use the CLI for interacting with other tools, regardless of language.) – mario Dec 29 '16 at 21:31
-
use shell_exec(), exec() for linux command execution. – Eugen Dec 29 '16 at 21:35
-
Unix Gimp for this is complete overkill. – xenoid Dec 30 '16 at 09:05
3 Answers
There is also the GD library which can be used with PHP directly.
http://php.net/manual/en/ref.image.php
imagecrop — Crop an image to the given rectangle
imagescale — Scale an image using the given new width and height
First thing: for resizing or cropping, you really should use some PHP library that integrates with Imagemagick, or something along that.
Now, to actually answer the question "is there any way to connect GIMP with PHP?" - The answer to that is "not directly".
Supposing you want to do extend use of Image manipulation algorithms for some serious project - GIMP engine nowadays is driven by GEGL (Generic Graphics Library) - which has support to binding with any other language through gobject introspection. Now,, gobject introspection can theoretically work with any language - but looking for Gobject Introspection for PHP yields some blog postos form 2011, and some early-stage projects on github. Therefore, although GEGL is what could provide you full image maniulation capabilities, I don't think it can be directly itegrated with PHP due to missing gobject integration. There should be a lot of ways of usig it indirectly, though - by creating some local web-service that would use GEGL to process operations described in XML, for example - such a service could be made in Python or C.
And, finally, for using GIMP's PDB itself, one could craft a Python script that would work as a local webservice relay to GIMP's PDB -so it is also possible in an indirect way.

- 99,910
- 10
- 151
- 209
I like the ImageMagick library, it is more powerful than the GD library. However it doesn't come pre-installed with php you have to do it manually, but if you can do it, it's easy to install with:
sudo apt-get install php5-imagick
The website: https://www.imagemagick.org
The PHP docs: http://php.net/manual/en/book.imagick.php

- 34,175
- 38
- 176
- 338