About adding watermarks to images

Source: Internet
Author: User
Tags imagejpeg
I wrote a collection program to add watermarks to images. online images are collected with a bunch of garbled characters.
Header ("Content-type: image/jpeg; charset = utf-8"); then the normal image is displayed
Now I want to add a watermark to the image.
I saved the collected images directly to the directory and then loaded them as follows:
$ Fp = @ imagecreatefromjpeg (image path );
$ Wp = @ imagecreatefrompng (Watermark path );
$ Res = imagecopy ($ fp, $ wp, 0,120,180, 0 );
Imagejpeg ($ fp );
Now I want to add a watermark directly to the directory without saving it. how can this problem be solved? please kindly advise. thank you!


Reply to discussion (solution)

I don't understand. do you have to store your data somewhere?
The imagecreatefromjpeg () function of php supports the rfc2397 standard. you can use

$ Mime = 'image mime type, such as image/png, image/jpeg '; $ base64_content = base64_encode ('image content'); $ uri = "data: {$ mime }; base64, {$ base64_content} "; $ fp = @ imagecreatefromjpeg ($ uri );

Or you can save the image to a temporary folder, which is more convenient.

Program on SAE and BAE
It is relatively difficult to save images and drop them into storage.
Besides, I do not want to save images.
So you can ask if you can directly add the watermark output without saving it.

Isn't there imagecreatefromstring?

$fp = imagecreatefromstring(file_get_contents('http://avatar.profile.csdn.net/9/D/6/1_dream1206.jpg'));$wp = imagecreatefromstring(file_get_contents('http://avatar.profile.csdn.net/1/5/6/1_gilper.jpg'));imagecopymerge($fp,$wp,0,0, 0, 0,120,180, 50);imagepng($fp);

Previously, we have studied how to use imagemagick to add watermarks with powerful functions. You can see

The forum is very good. I understand a lot.

Isn't there imagecreatefromstring? PHP code? 1234 $ fp = imagecreatefromstring (file_get_contents ('http: // batch); $ wp = imagecreatefromstring (file_get_conten ......

Thank you very much. we have done this. we have not found this function before.
First, ask a question. use
Header ("Content-Type: image/jpeg ");
Imagejpeg ($ fp );
In this way, the file has been declared as an image and cannot be directly associated with the original HTML. how can we directly echo the image somewhere in HTML?
I know that I can't use the img label to load another webpage. please refer to other methods. thank you.

You can use iframe or css as the background without img.

You can use iframe or css as the background without img.
In special cases, you can only output data on this page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.