I might miss something here but that doesn't seem to be an issue here. Photos uploaded prior to validation are flagged for pending moderation, right? So you have them showing up in your moderation queue. And once you validate them, you add the watermark.
Watermark images
I have a situation where i need to add a watermark to an image already uploaded.
Basically a user can upload images (Photo model), no problem there. A user can also upload supporting documents (Document model) that are used to verify the user. If a user is verified any uploaded images get a watermark image applied. That works fine, no issue.
So in the admin backend, I can moderate the image and say yes its verified, Problem is a user has images uploaded (Photo) prior to uploading the supporting documents (Document) and having the image being verified. Document uploads are not required so I can not force a user to provide them prior to Photo upload.
How can i watermark the images (Photo) already uploaded?
@axeloz Somewhat correct. The images will get moderator review but they are still public automatically. They (Photo) are publish regardless of being verified (Document) supplied or not. A photo might get pulled if deemed racists / sexual / or along those general lines, but other wise they will get posted.
Think of a news report that might come from a verified source or from an unknown source. Both will get published; its just 1 might be more trustworthy. But unlike a news article where we could simply add "verified" text to the article, in my case I need to add a verified watermark to the images.
Scenario: I upload an image to my account. And then i see ohh I can have my photos / account verified for greater trust so i then upload my supporting docs. My images are on my profile prior to the supporting docs. Admin reviews my docs and says yes you are now verified.
I need laravel to now get those already uploaded images and now add the watermark and put them back
Then add a verified_at timestamp to your Photos. null is the default. You'll know which were verified or not and which need to get a watermark.
I know which files will need to get watermarked, it's how do you watermark an image thats already uploaded.
Normally you add the watermark at the time of upload. Files are already uploaded in this case. What is the proper process to add the watermark after the fact?
Pull the unmarked files down in the backend and create a new image all over again then add the waterwark and re-upload the same image again?
Uploaded file => /users/image/1.jpg has no watermark
Admin says ok this file look good and user has provided docs so its also verified, DB updates 1.jpg verified = > true So how do we get the watermark on 1.jpg
OK I got it, but once again, I don't really see the issue. What I would do would depend on the number of images to process. If it's just between 1 and 5 at every batch, that could be a foreground job when you moderate them. Using Laravel Storage:: or the stock GD library, or any other watermarking package, you get the original image, you create a GD copy, you watermark, create the new file, change the filename and path into DB and optionally delete the original file. I would rather avoid overwriting the original file in case something nasty happens.
The other option is the Laravel console command: it runs every X minutes and process all the images as batches.
For instance https://packagist.org/packages/intervention/image Integrates with Laravel
Sorry man, you still are not following.
I know how to add water marks when the image is uploaded.
Example: At the time of upload.
$img->resize(800, 1200, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->insert($watermark, 'center')->encode('jpg', 75);
I am asking how to do it AFTER the image is uploaded.
Is there some method or package that can do it AFTER the fact or do i simply needed on admin side make a method to pull the images requiring a watermark added and repeat the process all over?
Because I am not allowing fopen so laravel intervention can't simply pull the file from S3 and add a watermark and put it back to S3
I would need to get the url, convert to base_64, create a new image from that data, add the watermark and save the image replacing the original,
Thants what i am asking. Is that the only way or is there something I am missing that would make the process easier?
Either way i will mess around and come up with something.
Thanks for your time all the same.
@movepixels I think I replied to this question. Intervention/image can read images from various ways including from URL fetch. Doc : https://image.intervention.io/v2/usage/overview#reading-images
If you want to avoid downloading and reuploading the image, then keep a local copy of the original images. Add watermark and just reupload it. Obviously that won't work for old images if you didn't keep the local version yet.
@axeloz I cant simply get the image from S3 -> URL of an image (allow_url_fopen must be enabled) I do not allow this. I know how to do all of this, i am not asking how to do it code wise. I know "how to code it" I am asking as in what is the best way or am i missing something.
To me having intervention go to S3 and get the file , read / convert as a base_64 and to encode and make::image and apply the watermark and push it back to S3 and all the steps involved seems like a lot of work so i was asking if there is a simple way.
But either way i give up and simply have 2 versions of the image, marked and un-marked. If not veriifed use the unmarked image, if verified use the marked. S3 storage is cheap and it's only 1 extra col in the db and problem solved :)
Here is a working version so it was not as complicated as i first thought. Could use refining but if anyone comes across this topic:
public function update(Request $request, Profile $profile, Photo $photo)
{
$s3 = \Storage::disk('spaces');
$remote = $photo->image;
$file = $s3->get($remote);
$manager = new ImageManager();
$img = $manager->make($file);
$verifiedSeal = public_path('images/photo-verified-watermark.png');
$img->insert( $verifiedSeal, 'bottom-left', 10, 10)
->encode('jpg', 75);
try{
$s3->put($path, $img->stream('jpg', $this->compression), 'public');
} catch (\Exception $e) {
throw new UploadFailed(13212);
}
return new ReviewablesPageCollection($profile);
}
Please or to participate in this conversation.