Is there a way to copy an uploaded image in the assets.onSaveAsset event?
I want to make a copy of the original uploaded image (for internal purposes) and after that I want to add a copyright text on the uploaded image (for displaying on webpage).
UPDATE Some more info, to prevent missunderstandings: I use the BusinessLogicPlugin. Users can upload a picture which should be stored in S3. First I want to make a copy of this picture and after that to the picture should be added a small text. The copy works fine.
But now I want to modify the uploaded image.
My Code:
craft()->on('assets.onSaveAsset', function(Event $event) {
static $recursionLevel = 0; // is set only once
if ($recursionLevel == 0 ) {
if ($event->params["isNewAsset"]) {
$recursionLevel++;
$asset = $event->params['asset'];
$remoteFile = $asset->getUrl();
// get remote image and store in temp path
$imageInfo = pathinfo($remoteFile);
$tempPath = CRAFT_STORAGE_PATH . 'runtime/temp/' . $imageInfo['basename'];
file_put_contents($tempPath, fopen($remoteFile, 'r'));
// only JPEG allowed
$im = @ImageCreateFromJPEG ($tempPath);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// add text and save to original path
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);
imagejpeg($im, $tempPath);
// update the image, but how?!
}
}
});
How can I update the asset with the new generated file in $tempPath?