PHP GD Image Watermark Quality - php

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/

Related

compression of 100 still loses quality on PHP GD

When I Use:
imagecreatefromjpeg() and the $path parameter is a URL. I save the jpeg at 100 compression... Yet I still get slight quality loss...
Is there a way to prevent this?
There is always a loss in quality when you re-save a jpeg image, you should instead copy the image file.
all jpg images will have artifacts, no matter the compression. if this is a picture with lots of colors and no real sharp edges it shouldnt be a problem, however if its a logo or something where edges are important you should consider using the PNG alternative.

resize the img i get from facebook

is there a good way to get the large image and resize it / slice it so the img will not loss her quilaty and aspect ratio in php?
10x
Yes.
Getting the image can be done with cURL for example. See http://de2.php.net/manual/en/book.curl.php
Resizing can be done with PHPs GD img functions http://de2.php.net/manual/en/book.image.php
or for better quality on resizing you can use ImageMagick or Cairo, which (at least ImageMagick definitely) require third party tools as well though. So only PHP will not be sufficient there. http://de2.php.net/manual/en/refs.utilspec.image.php

User name as Watermark

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

PHP GD library losing quality. Other ideas?

So I'm in the middle of working on a website that deals with photographs. A user uploads their original photograph and GD library creates a smaller sized image of the same photo. However, when comparing a manually sized down image with the GD one, the GD image seems to lose quite a bit of color quality like it had been slightly desaturated. Any alternate suggestions or ways to improve this?
Thanks!
I'd advice using imagemagick for handling anything serious about photos.
besides quality, you'll find using imagick functions like more convenient
Imagick::cropThumbnailImage()
Imagick::thumbnailImage()
Use imagecopyresampled instead of imagecopyresized. It gives much better quality. Also, try NOT to use GIF images as output.
Wow, the answer is imagemagick. Easier to use and maintains the full photograph quality!

phpThumb - change watermark size

I'm using phpThumb in a script to clean my images and add a watermark to them. We have images of very different sizes (from 100px width to 800px), so no matter what watermark image I use, it's either going to look too small or too big on the image.
Do you know of a way to tell phpThumb to resize the watermark? Or is there a way to resize the watermark image (depending on size of image being watermarked)?
Thanks a lot guys!
Ali
I am facing the same issue.
Maybe you could put some if statements in the phpthumb.config file in the DEFAULT PARAMETER SECTION
then depending on the height and width parameters you can decide to use different files with varying sizes for the watermark.
make sure you change $PHPTHUMB_DEFAULTS_GETSTRINGOVERRIDE to false
This is not perfect cause you could not know the source image size to start with.
but it would be a better fit based on the parameters passed to phpthumb.
I guess the only other solution would be to use phpthumb as an object but that would require a lot of work.

Categories