0

I have been tasked with a problem where i need to pickup one image froma set of 1000 and serve it to the user based on the parameters passed in the get query. This was simple. Adiditonally, i have been asked to serve the image in such a way that even if the same file is server everytime, the sha1 hash of the image file should come different.

To achieve this,We could just add random pixels in the image background at random places.

Can somebody tell me how i can acheive this using the GD library

4

1 に答える 1

0

Imagesetpixelを使用します。

$img = imagecreatefrompng('your_image.png');
$red = imagecolorallocate($img, 255, 0, 0); 
imagesetpixel($img, $x, $y, $red);
........
........

一方、リクエストごとに画像の sha1 ハッシュを変更する必要があるのはなぜですか?

編集:透明なピクセルが必要なので、 imagealphablendingと次のようなものが必要になります。

$img = imagecreatefrompng('your_image.png');
imagealphablending($img, false);
$transparent = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagesetpixel($img, $x, $y, $transparent);
imagesavealpha($img, true);         
imagepng($img, 'my_saved_file.png');
于 2012-05-29T14:06:24.043 に答える