By mpeg on 2008, August 2, 7:55 PM
This example demonstrates how Imagick can be used to create graphs. This graphing class itself is mostly a demonstrative example. There are also some hardcoded values in the graph (like the steps in the values on the left hand side) but it should not be hard to refine it into a more elegant graphing solution.
The graph is generated using the ImagickDraw drawing features. Since the ImagickLineGraph class extends the ImagickDraw class the instance of it can be passed directly to the Imagick::drawImage method.
The ImagickDraw class behaves a little like a ”drawing stack”; you can perform multiple operations on the object and then render the operations on a canvas. Operations like rotate and translate take affect on all drawing operations executed after them.
Here is the generated graph:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1239
By mpeg on 2008, August 2, 8:51 AM
Now it's time to take this example a little further by creating an effect which looks like you have a stack of polaroids laying on your desk.
The resulting image looks something like this:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1280
By mpeg on 2008, August 1, 10:49 AM
The image is first scaled down to create a thumbnail. Imagick::thumbnailImage also strips all the associated profiles to make the image optimal to use in web applications.
The next step is to round the corners of the image. This is pretty trivial task but you should keep in mind that usually larger x and y rounding values give the optimal results when rounding the corners of a larger image. Generally it is pretty easy to find the suitable values by poking around with the parameters and making a formula out of it.
The final step is to create the drop-in shadow and composite the thumbnail over it. I use compositeImage in this example because Imagick::shadowImage creates only the shadow.
Once again, the original image:

And the results:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1450
By mpeg on 2008, August 1, 10:20 AM
This example illustrates making an animated GIF image by creating the frames from scratch. It's been so long since I've really drawn anything so I decided to use text as the base for this animation.
You could of course use existing images to simulate motion or even strip frames from videos to create GIF animations.
This is how the resulting image looks like:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1460
By mpeg on 2008, July 31, 3:17 PM
以前在打水印的时候经常会遇到一个问题,比方说水印的颜色是黑色的。但图片背景也是黑色的。那水印打上去等于没打。
Usually images are watermarked using a predefined color (let's say for example "white"). How well does this actually work when you're doing the watermark on a light or even a white image? The answer is simple: not very well.
This example illustrates how to use ImagickPixelIterator to get the average luminosity of the background and chosing text color according to it. I tested this algorithm very briefly and the results seemed positive. There's four example images posted at the end of this post to show why background matters when doing a watermark.
Here is strawberry.png with black watermark (this was chosen by the script):

And here is strawberry.png with white watermark:

Image32.png with white watermark (this was chosen by the script):

Image32.png with black watermark:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1779
By mpeg on 2008, July 31, 11:05 AM
Imagick provides various ways to identify image properties. These properties include for example some basic attributes like width, height, format and some more advanced attributes like exif tags, profiles and colorspaces.
This example will demonstrate a few basic ways to read these attributes from an image. The image used in this example is from www.exif.org and can be found here http://exif.org/samples/fujifilm-dx10.jpg.
The support for getImageProperties and getImageProfiles was added in ImageMagick version 6.3.5-9 and Imagick version 2.0.0RC4.
» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1291
By mpeg on 2008, July 30, 5:16 PM
The code creates three different "palettes" from image; average palette, dark palette and bright palette. I got the idea for three different palettes from MarcosBL at freenode.
The first source image:

The created palette:

The second source image:

And the palette:

And one more:

Palette:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1676
By mpeg on 2008, July 30, 3:45 PM
This example will work with Imagick 2.1.0 (the RC1 was released yesterday) but with a little tweaking it should work with 2.0.x too.
The source image:

The result image:

» 阅读全文
Tags:imagick | imagick | Comments:0
| Trackbacks:0
| Read:1193