My client needs for his visitors to be able to upload, zoom and crop an image, add text over the cropped image and choose a position of the text.
Something like example on this image: http://devadesign.biz/example.jpg
After clicking on submit button the cropped image, with text on it, has to be saved in a specific folder.
Is there any plugin or tutorial for something like that?
I've already tried some plugins and scripts like those:
https://artisansweb.net/upload-crop-resize-image-using-jquery-php/
https://www.sanwebe.com/2012/05/ajax-image-upload-and-resize-with-jquery-and-php
https://www.sitepoint.com/crop-and-resize-images-with-imagemagick/
http://www.croppic.net/
https://foliotek.github.io/Croppie/
...but none of them supports adding text.
Thank you!
You can do that in Imagemagick. Here is an example:
Input:
line 1: read input and put into memory and delete input
line 2: add contast to memory input
line 3-5: add white to memory input
line 6-7: create a white image with a black rectangle in the middle as a mask
line 8: composite the two modified input images using the mask
line 9: set up the fill and stroke for creating a black outline around the middle
line 10: draw the black polygon rectangle
line 11: set up the pointsize and colors for the text
line 12: draw the text with annotate
line 13: save the output
convert lena.jpg -write mpr:img +delete \
\( mpr:img -level 10x100% \) \
\( mpr:img -alpha set \
-channel a -evaluate set 80% +channel \
-background white -flatten \) \
\( -clone 0 -fill white -colorize 100 \
-fill black -draw "rectangle 64,64 192,192" -alpha off \) \
-compose over -composite \
-fill none -stroke black \
-draw "polygon 64,64 192,64 192,192 64,192" -alpha off \
-gravity center -pointsize 24 -fill white -stroke white \
-annotate +0+0 "TESTING" \
result.png
For drawing options see https://imagemagick.org/Usage/draw
Wordpress has an Imagemagick plugin. See https://wordpress.org/plugins/tags/imagemagick/
Related
I want make 2 different colors on the output image when using Imagemagick. I have an original image with "Hello World" in it. And a modified image with "Hello Warcraft" in the same area. The default compare command will give me a image and mark all the differences with red.
Now I want to use 2 different colors like "orld" marked as red, and "arcraft" marked as another color, maybe blue. Is ImageMagick able to do this?
If not, how to use ImageMagick to transfer a specified color to another one?
Below are the sample.
Image A
Image B
Then I use the compare like: compare imageA.png imageB.png imageC.png
then the Image C will be:
Image C
But now I just know there are some differences between Image A and Image B. so I want to make some color-code on the Image C, it could be like below Image D:
Image D
from this I can know which parts are the same, and Green means what the difference on Image A and Red means what's the difference on Image B.
You can do this in ImageMagick 6 (Unix Syntax).
ImageA:
ImageB:
convert img1.png img2b.png \
-define compose:args="0,1,-1,0.5" \
-compose mathematics -composite -auto-level \
\( xc:red xc:blue +append \) -clut diff.png
This is a biased difference. Anything above 0.5 or mid gray (in normalized values) will be one color corresponding to one image and anything below 0.5 will be the other color corresponding to the other image.
See clut and compose mathematics
For ImageMagick 7, change convert to magick.
ADDITION:
Given your new input images. Here is how to do that:
imageA:
imageB:
convert imageA.png imageB.png -write mpr:img +delete -fill white -colorize 80% \
\( mpr:img -compose minus -composite -threshold 0 -background red -alpha shape \) \
\( mpr:img +swap -compose minus -composite -threshold 0 -background blue -alpha shape \) \
-background none -compose over -flatten result.png
Sorry, I used blue in stead of green. But you can change that if you want.
I have two images:
a.jpg
b.jpg
Both images are square (100x100 pixel). I want to cut a circle with a radius of 50 from image a.jpg and paste it in the middle of image b.jpg. I want to save the result in c.jpg.
How can I do this with Linux command line tools? I need to do it within a shell script.
Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.
convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg
For example...
convert -size 100x100 PLASMA: a.jpg
convert -size 100x100 GRADIENT:LIME-ORANGE b.jpg
convert a.jpg b.jpg -fx 'hypot(50-i, 50-j) < 50 ? u : v' c.jpg
Update with another technique.
A faster approach can be leveraging image mask(s) of the shape you wish to crop, and compose/composite it between both images. It'll require a format that supports alpha channels, but only for the initial work. For example...
Create a circle mask, and copy values to alpha channel.
convert -size 100x100 xc:White -fill Black \
-draw 'circle 50 50 50 5' -alpha Copy mask.png
convert \( a.png mask.png -alpha Set -compose Dst_Out -composite \) \
b.png -compose Dst_Atop -composite c.png
Eric's approach is much more succinct, and probably preferable, but here is another way anyway. I am being very environmentally aware and recycling ;-) his start images:
magick b.jpg \( a.jpg \( +clone -threshold 101% -fill white -draw "circle 49,49, 49,99" \) -channel-fx '| gray=>alpha' \) -flatten result.png
That says... "Load b.jpg as the background. Load a.jpg and then create a transparency mask by cloning the entire a.jpg setting it black and drawing a white circle in it and pushing it into the alpha channel. Then flatten that over the top of b.jpg".
The result is the same as Eric's.
I want to loop through a folder of images and output to console how many pixels are #333212, how many are #332211 etc. Is this possible in PHP? I found a package that manipulates images but not one that can detect colors of each pixel. Does such a tool or function exist in the PHP library?
EDIT: Doesn't have to be in PHP, the less packages I have to install the better.
You can do this quite easily with ImageMagick, like this. Say we want to count the red pixels...
# First create a little test strip with black, white, red, green and blue parts
convert -size 50x50 xc:black xc:white xc:red xc:lime xc:blue +append out.png
Now convert anything non-red to black so that only red pixels remain
convert out.png -fill black +opaque red n.png
Now count the red pixels by cloning the resulting picture and making the clone fully black (by setting everything to zero), and running a comparison to count how many pixels are not black
convert n.png \
\( +clone -evaluate set 0 \) \
-metric AE -compare \
-format "%[distortion]" info:
2500
And 2500 looks like 50px by 50px to me :-)
Note
The AE is the Absolute Error, i.e. a simple count of the number of differing pixels. The -format "%[distortion]" info: part causes ImageMagick to output the count (%distortion) as a number (info:) rather than as an image.
Obviously, you replace red with "#333212" for your problem.
You can also do all that in one visit, like this:
convert input.png \
-fill black +opaque red \
\( +clone -evaluate set 0 \) \
-metric AE -compare \
-format "%[distortion]" info:
I am trying to replace the colour of some pixels in an image using imagemagick, BUT not in the whole image just within a part of the image.
The command I am using now is:
convert original_image.jpg -fuzz 5% -fill '#f2f2f2' -opaque white image_without_colour.jpg
This works but it replaces #f2f2f2 everywhere rather than just where i want i want.
I would ideally do something like:
convert original_image.jpg -fuzz 5% -fill '#f2f2f2' -area '100,100,50,50' -opaque white image_without_colour.jpg
I am thinking about a more elegant solution, but I think this does what you want:
convert x.jpg -crop 100x100+50+50 y.jpg # Extract region to work on into y.jpg
convert y.jpg -fuzz 5% -fill '#f2f2f2' -opaque white z.jpg # Do your stuff and save as z.jpg
convert x.jpg z.jpg -geometry +50+50 -composite out.jpg # Whack it back whence it came!
Output file isout.jpg
I think this is a more elegant solution:
convert x.png \( +clone -crop 100x100+50+50 -fuzz 5% -fill '#f2f2f2' -opaque white \) -flatten out.jpg
ImageMagick's "-region" option is equivalent to your suggested "-area" option:
convert original_image.jpg -fuzz 5% -fill '#f2f2f2' -region 100x100+50+50 \
-opaque white image_without_colour.jpg
changes white pixels in the specified region to gray.
I am trying to take an image, say front2.jpg and add "Hello World" arc'd across the top. But I can't seem to figure out how to get this working. I'm getting an errror
-bash: syntax error near unexpected token `('
Command
convert front5.jpg (-gravity north -pointsize 40 -fill '#ffffff' -background none label:'Hello World' -virtual-pixel transparent -distort Arc 320) -geometry +0+0 -composite front2.jpg
Like bash is trying to tell you: take out the parentheses.
convert front5.jpg -gravity north -pointsize 40 -fill '#ffffff' -background none label:'Hello World' -virtual-pixel transparent -distort Arc 320 -geometry +0+0 -composite front2.jpg
I grabbed a random jpg and tried this command on it and got a neat little text arc (that's a pretty cool effect by the way) on the result.
It also works if you escape the parens, but I can't find any noticeable difference in the result, so I'd just use the first one for simplicity.
convert front5.jpg \( -gravity north -pointsize 40 -fill '#ffffff' -background none label:'Hello World' -virtual-pixel transparent -distort Arc 320 \) -geometry +0+0 -composite front2.jpg