I'm looking to use a set of images that are white where color should be, black where it should be transparent, and gray in between, to generate patterns as PNGs in PHP. Is there any way to do this? I'm running PHP 5.4 if it helps.
Related
Ok, so I am taking full color PDFs and trying to convert them to black and white images to then make them black and white PDF's.
Currently I am attempting to do this with imagemagick and i am for the most part successful with breaking them PDF into separate images. However once creating the separate images I want to make full size black and white copies next to the color copies as well as thumbnails thereof of both. Which that part I feel I'll be able to figure out on my own.
What I am having trouble figuring out is how to get them to become black and white. Not necessarily grayscale, since grayscale will still use colored ink in most printers to come up with the varying shades of gray. From which I am trying to avoid.
Is there a means I can do this with imagemagick or is my thought process all wrong?
Also worth noting is I am trying to do this through a browser and server side process with PHP
I think you are looking for "Two Colour Quamtisation" as described in Anthony Thyssen's excellent work here.
Basically, you use quantisation to pick the best two colours to represent your image, then force the darker one to black and the lighter one to white. So your processing becomes:
convert image.png -colors 2 -colorspace gray -normalize result.png
Btw, I presume you found and are using pdfimages (part of the poppler package) to extract the images in original quality.
I have a task to write a PHP script that makes objects in the center of their pictures, For example
Some of the pictures are horizontally oriented and some are vertically oriented based on that and the size of the white space I have to Crop/Add white space to the original picture.
The first method I had is by detecting the borders of the object within the picture but some picture doesn't have clear white background e.g:
This Picture has extra white space on the borders and has gray gradient as the background which makes it harder to detect the object's borders, So I tried to apply The Sobel operator by Imagemagick
exec("convert 1.jpg -define convolve:scale='50%!' -bias 50% -morphology Convolve Sobel -solarize 50% -level 50,0% ssc1.jpg");
The result was ok
And Now I have to find the borders in the filtered image, And the question is
What's the best way to find the coordinates of the borders (the output should be X1,X2,Y1,Y2)?
I have read some similar problems like this one that converts the image to text and remove white (black in my case) pixels but I'm not sure what's the best approach to solve this (I'm newbie in Image Processing).
I don't have time today to do this in ImageMagick, but I did an experiment in Photoshop and it seems to work nicely - at least for your lady on a gradated background.
I took the image and duplicated its layer in Photoshop (Cmd+J).
I set the Blending Mode of the upper layer to Hard Mix
I did Image->Trim from the menu at top of screen.
There is a good explanation of how Hard Mix works here at the bottom of the page.
You could emulate the Hard Mix effect using ImageMagick's fx operator like this here
Hope the approach helps.
This might seems like a duplicated question, but I couldn't find exactly this scenario. Might be wrong though.
My problem is, say I have a square, $square, of 100x100 pixels inside a canvas of 150x150. Background is transparent.
I cloned the square and then I cropped the part I needed to work on ($detail).
I need to apply a gradient, top to bottom, on $detail so that the top part is around 60% white-transparent to a 100% transparent at the bottom.
Then, to compose $detail over $image.
I can't use convert, only php imagick functions.
Thanks in advance!
Will
convert has a special creation operator in recent versions for producing gradients, simply called gradient: - they are implemented as pseudo image formats.
Usage of the gradient: operator can get quite complex if you want non-vertical gradients or with transparency, so read the documentation. Be aware the underlying version of Image Magick will make a difference to how you have to go about it.
You can create pseudo-format images, using the IMagick operator: Imagick::newPseudoImage()
Once you have the gradient at the right size, you can compose it with your $detail image.
Generally, my tip with using things like IMagick, is to get the command right using convert first and then translate it to the interface.
I have logo parade in WordPress. All those logo are color RGB. I like the effect that look like. All the logo are b&W and then on hover it become color.
I know how to do it with sprite, but it just double each logo and i have a lot. i know it's possible to "process it" with php or JavaScript to "generate" the b&w version on the fly.
What will be the best way/code to do that ?
If you have a lot of images I would not recommend you to generate grayscale version on the fly. Better to prepare corresponding black and white version for each icon/logo. It's very easy to do for example with ImageMagick:
$ mogrify -channel RGBA -matte -colorspace gray *.png
This will conver all the .png images to the grayscale.
I have found that perfect solution (by luck) : https://github.com/GianlucaGuarini/jQuery.BlackAndWhite will try all and tell you wich one win, thanks !
Depending on the browsers you want to support, you may be able to do it using CSS filters. However, support for this is not very widespread at the moment.
And that wordpress technique look cool : http://bavotasan.com/2011/create-black-white-thumbnail-wordpress/
If you want do it for every image, you cane us this formula, using the range [0-255]:
Grayscale value = (0.299*r + 0.587*g + 0.114*b);
where r, g, b represent the red, green and blue values of the input images.
I've created my own algorithm to remove artifacts based on pixels. The only problem is that I have to manually specify the range of RGB based on a picture.
I'm trying to make it a bit more automatic, and have concluded that artifacts are usually very light colored and barely visible unless tilting the screen. Is there any RGB math that I can use to weed these artifacts out properly?
A basic way to do this is to use an adaptive blur on the image. Very close to white will be turned white, and so on, but edges will stay intact. Use ImageMagick, http://www.php.net/manual/en/imagick.adaptiveblurimage.php