How can I create kaleidoscope images like default avatars here at SO, using PHP?
I'm pretty sure the default generated images are actually generated by gravatar, more about that here: http://en.gravatar.com/site/implement/images/
According to them, they use the "identicon" which is actually based on the email.
http://scott.sherrillmix.com/blog/blogger/wp_identicon/
You can take a look at that code and see how it's generated :)
You can use Imagemagick binding to php.
Here are some distortion functions: http://www.imagemagick.org/Usage/distorts/
And here is kaleidoscope script: http://www.fmwconcepts.com/imagemagick/kaleidoscope/index.php
You can combine distortions and kaleidoscope to get nice pictures.
E.g. something like this (bash, not php):
$ mkkal='dx=i-50; dy=j-50; rad=hypot(dx,dy); tt=mod((atan2(dy,dx)+6.28319+0)*5/(6.28319),1.0); ang=2*(tt<0.5?tt:1-tt); u.p{50+rad*cos(ang),50+rad*sin(ang)}'
$ convert -size 100x100 pattern:checkerboard -distort Barrel '-0.2 -3.0 0.2 1.3' -fx "$mkkal" tile.png
$ display tile.png
Try different args to Barrel or different distortion methods to get more interesting results.
They are created by gravatar.com
Examplse: http://www.gravatar.com/avatar/78fg67b5c2c25634fgadd727f6b08?s=32&d=identicon&r=PG
Related
Good day. I am new to Imagemagick, and I just wanna ask what's wrong with this code
$cmd_for_wm = "composite -gravity southeast watermark.png image.jpg image.jpg;";
exec($cmd_for_wm);
When I run it in the terminal, it is working well, but when I incorporated it in PHP, it doesn't work. Why?
Thanks for you in advance :) Cheers
I've tried your example and it does "die" silently.
This, on the other hand seems to work:
$cmd_for_wm = "composite -gravity southeast watermark.png image.jpg image.jpg;";
passthru($cmd_for_wm);
Very curious indeed. Since the main difference between exec and passthru is the output handling. The later is used for binary data.
My take on this is that passthru correctly allows composite to output the processed image (which is binary data) into the specified file.
For a detailed explanation, please see PHP - exec() vs system() vs passthru()
How can I make a screenshot from every page of PDF file and save result as images in PHP? Is it possible?
Maybe the "make a screenshot" can be replaced for your purpose by "create a raster image" for each PDF page?
In this case you could use ImageMagick and/or one of its PHP-enabled libraries. Here is a command line representation:
convert some.pdf[15-19] some.png
This will convert not all pages, but the page range 16--20 (page counting here is zero-based (not intuitive, I know...). To convert all pages, just skip the [15-19] part.
The output PNG names will be some-0.png, some-1.png, ... some-4.png.
To create JPEG or GIF instead of PNG, simply use one of these:
convert some.pdf[15-19] some.jpg
convert some.pdf[15-19] some.gif
By default ImageMagick will use a resolution of 72 PPI. This will indirectly determine the image dimensions of the PNG/JPEG/GIF output. Should you need other output dimensions than the defaults, you have different options, for example:
either add -density
or add -resize
to the command line:
convert -density 200 some.pdf some.png
convert some.pdf -resize 50% some.png
I want to be able to detect whether an image is transparent or not using the Imagick PHP extension.
So far, the only luck I've been having is to run the exec() / some other command, and use the ImageMagick command line tool to achieve this. Here's what I mean:
exec("identify -verbose example_transparent_image.png | grep \"Alpha\"", $output);
$is_transparent = !empty($output) ? true : false;
The logic is simple. Do a verbose check on the image in question: if the output contains any alpha information, that means it uses transparency.
It seems that the PHP imagick extension should have this as one of its commands, but the lack of documentation is killing me. It seems silly to have to run this kind of check each time.
Ahhh, solved (I think). Imagick has a function getImageAlphaChannel() which returns true if it contains any alpha information and false if it doesn't.
Make sure you have ImageMagick 6.4.0 or newer.
http://www.php.net/manual/en/function.imagick-getimagealphachannel.php
Maybe this
http://ru.php.net/manual/en/function.imagick-identifyimage.php
What's about this?
substr((new Imagick($FILE))->identifyImage()['type'], 0, -5) == 'Alpha'
look at the documentation of identifyImage. You will notice the missing documentation of the functions output. It's just a parsed version of
identify -verbose $FILE (from the imagick package)
where type identifies the image's type (compare source).
You can see that imagick returns the value from some MagickTypeOptions array which is defined here. This array contains an -Alpha and -Matte version for every image type if it's color palette contains alpha.
Theoretically you could save an image with such palette without using it, but every decent programm should swith to the non-alpha version in this case. But false positives are possible but should be rare.
Also I don't check for the -Matte image types because in the array is defined in a way that for every image type constant there are two entries with different names (-Alpha and -Matte), but as -Alpha comes first this name will be returned for that image type.
I'm trying to convert a PDF to an image and I need to make sure that the -dUseCropBox parameter is specified for when calling Ghostscript. Can this be done?
convert "/var/www/vhosts/site.co.uk/httpdocs/uploads/source_pdf/PP4SDpdf.pdf" -resize 500X500 "/var/www/vhosts/site.co.uk/httpdocs/uploads/image_pdf/SaturdayTest.jpg"
It works well but just need to get the Ghostscript parameter in.
Is it acceptable for you to run Ghostscript directly (instead of having convert call it anyway) ?
I ask, because convert does not do the PDF => JPEG conversion by itself. It calls Ghostscript as its 'delegate' to do the job. So for convert to work you need to have access to a functional Ghostscript installation on that system anyway... .
But how to add custom parameters to converts commandline to pass them through to Ghostscript's commandline isn't easy to figure out. Ghostscript's commandline isn't exactly easy either, but at least it is fully documented at a well-known place (see Use.htm, Devices.htm and Ps2pdf.htm there).
Here is a command that would convert your input PDF to a series of JPEGs (one file for each PDF page). I'm assuming Windows -- for Linux just replace the ^ by \ and gswin32c.exe by gs:
gswin32c.exe ^
-o "d:/path with spaces/to/output/dir/input_page_%03d.jpeg ^
-sDEVICE=jpeg ^
-dJPEQ=95 ^
-r720 ^
-g5000x5000 ^
-dUseCropBox=true ^
"d:/path/to/input.pdf"
Explanation:
-dJPEGQ sets the JPEG quality. Accepts integer values in the range 0..100. Higher values create bigger files... (Ghostscript's default for JPEGQ is set to 75.)
-r720 sets a (rather high) resolution of 720dpi. Higher values create bigger files... (Ghostscript's default for its jpeg output device would be 72dpi.)
-g5000x5000 gives the file dimension in pixels. (Note: when decreasing the -r... value you MUST also accordingly decrease the -g... value to keep the same dimension in userspace inches or mm.)
You could also add -dPDFFitPage=true if that is useful for you.
The switch for imagemagick (the convert-command) is:
-define pdf:use-cropbox=true
see http://www.imagemagick.org/Usage/formats/#ps_reading
I would like to script PHP/ImageMagic in order to produce the "shadow" of a given image. Like in this example (done manually in GFXeditor) :
original shadow
alt text http://uppix.net/d/a/f/dc82fce795fc4af20170080b09c9a.png ==> alt text http://uppix.net/8/9/9/b1e9df4b2858c40081771961e028d.png
Note: All the originals images will be on a white background like in the example.
I've check the ImageMagic documentation but I haven't found anything useful yet. Does anyone know if it can be done in PHP/ImageMagic ? If so how ?
Use convert with -threshold option?
EDIT: oops... from PHP? Imagick::thresholdImage?
I wonder if it isn't more like a mask than a shadow? In the context of IM, shadow looks like a blurry copy of the image.
Try the edge detection chapter in the ImageMagick examples.