is there any way to connect GIMP with PHP? - php

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

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.

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

Related

How to create avif files in php?

Does anybody know how to write avif image files in php?
For webp files i have the function imagewebp. But avif?
Using PHP Version 7.4, 7.1 and 7.2 on different servers.
thanks a lot
EDIT:
It has been implemented in PHP 8.1 https://php.watch/versions/8.1/gd-avif
There is no dedicated function to do that at this moment. GD has implemented AVIF support but is not yet implemented in PHP. They are working on it https://bugs.php.net/bug.php?id=80828 , please vote for it.
Until that function is made, I image there can be other methods to create:
(1) using php exec/shell_exec and an command line app (like imagemagik). untested code:
if (function_exists("exec")) {
$command = "convert -size 600x600 canvas:white white.avif ";
exec($command, $output);
print("<pre>".print_r($output,true)."</pre>"); //debug
}
else {
echo "EXEC function is not available. See php.ini disabled_functions.<br />\n";
}
(2) using a php module like Imagik
https://www.php.net/manual/en/book.imagick.php
Verify ImageMagick installation
For both methods you need to make sure you have a recent version of ImageMagik compiled with proper libraries.
https://github.com/ImageMagick/ImageMagick/issues/1432
Unfortunately, there is no native PHP support (in any PHP version I know of) for the AVIF/AV1 image file formats, at this stage.
PHP normally relies on the GD, the ImageMagick, the GMagick (and Exif) image libraries, so - until these include support for the AVIF/AV1 image file formats, I'm afraid there won't be an easy (and "native") solution for you. There may be some third-party libraries, perhaps written in pure PHP, to support this, however the format is relatively new and not quite yet widely supported, so I believe it will take some time for these to be available, and a pure-PHP library for image processing is likely to be quite inefficient, performance-wise.
That said, I suppose you could consider using a workaround, which is PHP-generating an image in any of the other image formats (say JPEG or PNG), and then using a command-line tool to covert the resulting image file into AVIF/AV1?
See for example https://reposhub.com/rust/image-processing/kornelski-cavif.html
Good news - the work's been done to support AVIF in libgd, and this work has been propagated into PHP. It should be released in PHP 8.1.
Enjoy!

Imagemagick exec and convert

I recently started using imagemagick with php and
I'm relatively new with both of these, IM and PHP.
So, I'm here to ask for some help/suggestion(s).
First
If lets say a user uploads a gif or a png image on
my site and I want it converted to jpg, is there any
command like for example.$image->convert($file,'.jpg)
or the convert command is accesible only thru exec() ?
like for example exec(convert picture.png to picture.jpg)
Second
What if for again, the user uploads gif/png on the site
and I resize the image to a specified width/height and
write the image, with the writeImage function of IM like this:
$image->writeImage(basename.$ext) where $ext = jpg.
Will this work properly,is this a good practice? I assume this will
only rename it but still, I don't see a problem in this... o.O
Oh sorry one more question, I'm not very familiar with exec,
is it better using imagemagick using exec(), does it improve
speed, load etc?
I can't answer your questions directly but thought I point you to a few resources:
Regarding which is better, exec or the PHP extension, I asked this same question a few months ago:
Should I use a PHP extension for ImageMagick or just use PHP's Exec() function to run the terminal commands?
For all Image Magick PHP functions you should look up the official guide:
http://www.php.net/manual/en/book.imagick.php
I switched from Image Magick to Graphics Magick as I heard it has better performance. It is a fork of Image Magick with an emphasis on performance. Large sites like Flickr and Etsy use it:
http://www.graphicsmagick.org/
This guide got me started:
http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/
And they have their own manual on php.net:
http://php.net/manual/en/book.gmagick.php (most of the commands are identical to Image Magick's)
I prefer using exec() as it is supported a lot better than Imagick ( the example code you posted ), easier to use and supports all the operators ( depending on your version ) which again Imagick does not.
Some of the Imagick code works differntly in the different versions; there are a lot more Imagick examples around than there were a couple of years ago when I first started looking at it.
Saying that Imagick can be faster and is/can be? built into php although some people have trouble installing it.
I belive that this site http://valokuva.org/?cat=1 belongs to a Imagick developer and has lots of examples.
My site www.rubblewebs.co.uk/imagemagick has lots of examples of php with exec( )
As to your other two questions yes you can change the file type with Imagick and I am not sure about basename.$ext - why not try it? As long as basename does not have an extension it may work but you might need to include basename.$ext in quotes.
As to speed it dpends sometimes GD is faster other times Imagick or Imagemagick. You can always do some tests. I did some a year or so ago and you can try the code on your server. http://www.rubblewebs.co.uk/imagemagick/speed/Speed_tests_1.pdf

RAW images and PHP

I would like to extract a thumbnail from a RAW image file, like Canon's .CR2 or Nikon's .NEF. I've understood that this can somehow be done with ImageMagick, but haven't grasped if it's possible through the PHP wrapper.
Are there any good solutions? Preferably using the built in thumbnail for speed.
Yep, iMagick (the php version of ImageMagick) can handle these extensions: http://www.imagemagick.org/script/formats.php
Here's a great set of tuts that got me going with Imagick. The owner responded to a few of my questions quickly, and despite a bit of a language barrier was able to easily get me through my hurdles
As an aside, I've begun using Gallery to do image admin. No need to worry about thumbnailing, uploading, etc....it's all automatic. Then on the front end I can do jquery magic (getting photos via php query from the gallery database tables) to make it look really good.
Likely, if PHP's imagemagick libraries are to support this, they would be drawing from some functionality exposed through imagemagick's 'identify' command line tool (as the tool would be itself exposing functionality in the imagemagick libraries). Looking at the documentation for this tool, it doesn't look good. If you tried running identify -verbose, theoretically, the thumbnail information would appear in there somewhere, perhaps as an encoded value. Try it yourself: if it does, maybe you could possibly further extract the information returned from identify, either through the imagemagick functions in PHP (though I don't see any past the Exif libraries which only work on JPEG), or by scraping the return of a PHP system call to the identify tool.
Either way, doesn't look likely.
Benjamin Horn has submitted a complete example about reading the requested data and even saving it locally for later use.
Check this out:
https://benjaminhorn.io/code/extracting-thumbnails-from-camera-raw-files-cr2-and-nef-with-php/

What are the most used PHP image manipulation classes?

I am a newbie with php and I want to play with php and images uploaded.
What are the most used PHP image manipulation classes ?
If you're just starting I'd suggest taking a look at the GD functions. They come with PHP (assuming you have GD enabled).
If you need more power then there's ImageMagick, but you have to install it yourself.
Most used is hard to find but a large list of php classes can be found here:
http://phpclasses.fonant.com/browse/class/11.html
You can do alot with the built in GD graphics library:
http://php.net/manual/en/book.image.php
I am building an easy to use OO image manipulation library with intuitive API. Its publicly available on GitHub - https://github.com/avalanche123/Imagine

Creating text effects like curved, arched, wedged in ruby on rails or php

i know there is a convert -swirl effect in imagemagick but can i create other effects for text like curved, arched, wedged, pinched etc.. just like wordart in word.
i am open to other packages that might help me get this thing done.. php or ruby..
Here are some examples: http://www.fmwconcepts.com/imagemagick/texteffect/index.php
If you are interested, you can run this shell script through php exec() function or any other language which provide you with such an ability.
Check out RMagick, which is a Ruby interface to the ImageMagick library.
There are interfaces for many other languages as well, including PHP.
Look here for an overview.
As Lars suggested, RMagick is a good choice for doing it in RoR. If you're looking in PHP, I'm not sure that it can do some of the things you're wanting to, but GD2 (which is usually natively included with PHP if you installed PHP with a package manager) is a good tool. There is also a PHP extension for ImageMagick.

Categories