Home >Backend Development >PHP Tutorial >gd library - I beg you all, how can PHP automatically scale the watermark according to the image size?
Hello everyone, I am currently working on a watermark program, using the GD library. I want to put several watermarks on a picture, but the picture size is not fixed. As a result, the watermark is suddenly large and sometimes small. I pray to God to guide me, how can I achieve such a function?
Hello everyone, I am currently working on a watermark program, using the GD library. I want to put several watermarks on a picture, but the picture size is not fixed. As a result, the watermark is suddenly large and sometimes small. I pray to God to guide me, how can I achieve such a function?
Simple explanation of the solution logic, you will know how to write it after thinking about it.
Step 1: First set a picture size that matches the existing watermark. For example, pictures above 500*500 will look very beautiful after being watermarked.
Then it is very simple to solve the access problem. Get the width and height of the image. As long as it exceeds 500*500, go through the following process:
1: Calculate the ratio: such as 100*250, calculate the ratio, such as width/500=0.2 height/500=0.5
2: Scale the watermark and then paste it.
It’s explained so clearly that you should understand it.