Ok, I searched the internet and stackoverflow but I just can't seem to find an answer for my problem.
I need to watermark images uploaded by users dynamically, but I don't want just text applied on an image. I need a real watermark like this:
The only way I can achieve this effect is by using Photoshop, adding shadow and decreasing the filling to 0%. But if my site is visited by 200 users who upload their images, I just can't make for everyone of them a new PNG file with their user name. That's why I'm looking for a dynamic solution for this problem.
I already found classes how to add a png file as a watermark to images, but like I said before this won't work if my site is visited by a lot of users.
I hope someone knows a way how to solve this and get the same effect on images dynamically.
Thank you very much.
The documentation of the ImageMagick image processing library includes such a transparent watermark example. Even if you would like to use GD instead of ImageMagick, it might give you an idea of how to do it.
You can use imageMagick to do this with PHP. Do some Googling for PHP imagemagick watermarking, this thread may help some:
http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=17067
You essentially want to make a PNG file of your watermark. The PNG will allow for alpha transparency and you can get your drop shadow effect etc.
This will then be applied to your JPG image, and a final watermarked JPG image will be made with your PNG added on top of it.
Should work.
The other answers here are great answers, but I wanted to throw in an alternative.
You can dynamically build scripts for the GIMP to execute, which gives you tons of flexibility. This is way overkill for a simple watermark, but if you needed to do some more complex image processing, it is definitely an option. CoolText.com is an example of a website that does this.
The same approach should work in Photoshop as well. In fact, you could probably instantiate Photoshop's COM interface with PHP.
Again, I don't recommend this for basic watermarking... just if you need more functions than what is provided with ImageMagick/GD.
To the other answers I will add that you should not be generating the image on the fly. If the watermark is by username, generate the watermark file once when the user registers for your site (or changes their username), then use that file as an overlay for the uploaded images. This will save a lot of CPU time.
Use the following command:
magick convert input.jpg ( -size 960x640 xc:none -font microsoft-new-tai-lue -pointsize 90 -fill black -annotate +120+370 Watermark -blur 0x4 -fill none -annotate +125+365 Watermark ) -flatten output.png
Related
The effect I would like to generate is exactly like the example in
this StackOverflow thread: (Related Question)
1.Resize image
2.Keep proportion
3.Add or Fill none-image areas with white background
Here are three examples of this process below:
1. If original is square no matter 640*640 or 1024*1024, just resize it to target dimension e.g. 480*480 will work.
If the original input is vertical rectangular,the output should not be cropped
and still be centerlized as below (the red dash edge marker is just make it easier to see the background is white and the proportion is kept after image resized to 480*480 px)
if the original input is horizontal rectangular, output like below, white background, keeps proportion and image uncroped , thus without losing anything after the image processing.
So after I've clarified such a question,
I would like to know:
Is there a general name of such Custom Image Resize mentioned above?
would like to know how to achieve it using php image library Imagine?
is it doable using php-imagine, or have to switch to another library, e.g imagemagick?
P.S. If you would like to achieve the effect either in image-resizing or video resizing, you can use below FFMPEG single-line command.
(thanks to #Mulvya, yes below code applies both to videos and image formats)
[run below built-in code in ffmpeg console to achieve the mentioned resize effect]
[video resize]
ffmpeg -i "[raw video url or videofile location.mp4]" -vf "scale=iw*min(480/iw\,480/ih):ih*min(480/iw\,480/ih),pad=480:480:(480-iw)/2:(480-ih)/2:color=white" [save_path_and_filename].mp4
[image resize]
ffmpeg -i "[raw image url or imagefile location.jpg]" -vf "scale=iw*min(480/iw\,480/ih):ih*min(480/iw\,480/ih),pad=480:480:(480-iw)/2:(480-ih)/2:color=white" [save_path_and_filename].jpg
Sorry i don'T have full answer for you and it's too long for a comment, but this can be done natively using some maths and php's http://php.net/manual/en/ref.image.php
Check in the area of imagecopyresize() imageecreate() imagescale and so on. It a pretty complex lib so you will have to do some try and mistake to get where you want to go.
From experience you can:
create an empty image, imagecreatetruecolor()
change background color to white
take a scetion of an image and paste it in the new created image using imagecopyresample() imagecopyresize()
export this image ans gif, png, jpg. imagepng(), imagejpg().
add watermark
and ALOT more.
Sorry i don'T have a more complete answer but depending on your need it can take a few mitues/hours to make it perfect. have fun.
On top of it, if you know ffmpeg, you can make both work together and make awesome media outputs. Cheers to you
When a user upload an avatar for himself, I want to convert it into a circular image and then save it, as circular looks much more prettier when displaying in the page.
How can I do that in a simple way, as mine is a small application.
I have read about ImageMagick, but thats an option right now.
I read about masking or using another image as mask to do that.
Any simple method or way to do this.
Thanxx in advance!!!
The same as said before, the best option is store the image 'as is' and then apply rounded styles with css (this way you always have the original image).
But if it not work for you, you could use this: https://adamcod.es/2012/07/25/imagine-php-image-library.html && Crop image in circle (php)
Using imageMagik is this simple:
convert -size 200x200 xc:none -fill walter.jpg -draw "circle 100,100 100,1" circle_thumb.png
circularize an image with imagick
I have a default image that I want my users when they first create their profile to have, and I need to each one of them have a different background color but with the same base shape that will be in a png file, I can do this by creating for each background color create a png but I dont think it might be the best choice. How can I do this?
Use Imagick extension to work on your image. You can set a background color for your transparent png image by simply doing this
shell_exec("convert testimage.png -fill '#CCCCCC00' -opaque none image_wth_bgcolor.png");
This will give a slight gray(#CCCCCC) background to the the image.
See this link.
My suggestion is to create a png file for each colour (which seems to be the only way)
and use PHP to randomly pick one of the images.
Im trying to convert a PDF or JPG file into a png with specific colors being transparent.
For example. I have a file with white background and black text and would like to convert the white area to be transparent on the png
I have tried using imagemagick :
exec('convert -density 144 ' . $infile.' -transparent "#FFFFFF" ' .$png_file);
and this seems to work at times and not other times for some reason
also the edges of the black come out kind of jagged. Does anyone know of a way to make the edges smoother. or any other function in php to use to create the transparency.
Also the quality needs to be perfect as well as sometimes when the dimensions of the file are small the output png is very low res and i need to keep it at the same dimensions so i cant really use the -density function
You can overcome the jagged edges using the fuzz factor option -fuzz, but as the usage manual explains, the results may or may not fit your needs.
Background removal is also discussed at length in the usage manual, describing several techniques besides using the -transparent option.
Without more information, I don't know why your conversion code works sometimes and not at others, but I don't think you need the -density option for JPG conversion. That might be the problem.
I'am using PHP GD to copy an image (watermark) on another image.
Unfortunately the quality of the watermark is terrible.
I'm using quality 100% as the attribute, but it doesn't help.
Have you guys know any good way to increase the quality?
Regards.
A 90% quality should give you the exact same results and decrease the file size by half (on JPEG, OFC).
Try using ImageCopyResampled() instead of ImageCopyResize(), other than that I don't think you can do anything else with GD alone, maybe Imagick has some other tricks.
Are you using any transparency, or is it just a solid square. What exactly looks bad about the quality? The edges, the whole thing?
I like to use a 24bit transparent PNG for the watermark, and imagemagick to do the overlay, you get a lot of control over the final product that way.
Lots of possibilities for watermark with imagemagick:
http://www.imagemagick.org/Usage/annotating/