приветствую почитал погуглил но толком так ничего и не нашел нужно сделать чтобы при загрузке изображения на него накладывался водный знак(изображение) с учетом масштаба в произвольном углу изображения код функции загрузки Код: else if( $r[0] == 'upload' ) { if( $user->id ) { $uploadErrors = array(); if( $user->isSpamLocked() ) { $uploadErrors[] = 'No more than 10 images in 2 hours!'; } else if( !empty( $_POST ) ) { require_once( 'lib/imageuploader.php' ); if( ( !empty($_POST['url']) && ImageUploader::copyFromUrl( $_POST['url'], $_POST['tags'], false, $uploadErrors) ) || ( !empty($_FILES['image']['name']) && ImageUploader::process($_FILES['image']['name'], $_FILES['image']['tmp_name'], $_POST['tags'], true, $uploadErrors) ) ) { $cache->clear(); $user->logUpload(); header( "Location: ".Config::$absolutePath ); exit(0); } } include( Config::$templates.'upload.tpl.php' ); } else { header( 'location: '.Config::$absolutePath.'login' ); } } Код: <?php /* The ImageUploader class handles the insertion of images into the system - whether they were uploaded or should be copied from a remote URL */ require_once( 'lib/config.php' ); require_once( 'lib/db.php' ); require_once( 'lib/filesystem.php' ); require_once( 'lib/images.php' ); require_once( 'lib/users.php' ); require_once( 'lib/keyword.php' ); class ImageUploader { public static function copyFromUrl( $url, $tags, $referer, &$errors ) { if( stripos( $url, 'http://' ) !== 0 ) { $url = 'http://'.$url; } // no recursion, no non-images if( stripos( $url, Config::$frontendPath ) !== false || !preg_match( '/([^\/]*?)\.(gif|jpg|jpeg|png)$/i', $url, $fileMatch ) ) { $errors['downloadFailed'] = 'The Image could not be downloaded!'; return false; } $fileName = $fileMatch[1]; // use the domain name as part of the keyword $urlParts = parse_url( $url ); if( preg_match( '/(^|\.)([\w\-]+)\.\w+$/', $urlParts['host'], $m ) ) { $fileName = strtolower($m[2]).'-'.$fileName; } $fileName = Keyword::get( $fileName ).'.'.$fileMatch[2]; $targetPath = './import/'.$fileName; if( !Filesystem::download( $url, $targetPath, Config::$images['maxDownload'], $referer ) ) { $errors['downloadFailed'] = 'The Image could not be downloaded!'; return false; } if( self::process( $fileName, $targetPath, $tags, false, $errors, $url ) ) { return true; } else { @unlink( $targePath ); return false; } } public static function process( $name, $localPath, $tags, $uploaded = true, &$errors, $source = '' ) { $user = new User(); $user->login(); if( !$user->id ) { $errors['notLoggedIn'] = 'You are not logged in!'; return false; } // no non-images if( !preg_match( '/([^\/]*?)\.(gif|jpg|jpeg|png)$/i', $name, $fileMatch ) ) { $errors['wrongExtension'] = 'Your file has not the right extension (gif, jpg or png)!'; return false; } $time = time(); $keyword = Keyword::get( $fileMatch[1] ); // Iterate over all keywords, if this one is allready taken $taken = array(); $r = DB::query( 'SELECT keyword FROM '.TABLE_IMAGES.' WHERE keyword LIKE :1', date('Y/m/',$time).$keyword.'%' ); foreach( $r as $v ) { $taken[] = substr($v['keyword'],8); // Keyword without date! } $keyword = Keyword::iterate( $keyword, $taken ); list( $srcWidth, $srcHeight, $type ) = getimagesize( $localPath ); if( $type == IMAGETYPE_JPEG ) { $extension = 'jpg'; } else if( $type == IMAGETYPE_GIF ) { $extension = 'gif'; } else if( $type == IMAGETYPE_PNG ) { $extension = 'png'; } else { return false; } $thumbName = $keyword.".jpg"; // all thumbs are jpegs! $name = $keyword.".".$extension; $imageDir = Config::$images['imagePath'] . date('Y/m', $time); $thumbDir = Config::$images['thumbPath'] . date('Y/m', $time); $imagePath = $imageDir.'/'.$name; if( !Filesystem::mkdirr($imageDir) || !Filesystem::mkdirr($thumbDir) ) { return false; } if( $uploaded ) { if( !@move_uploaded_file( $localPath, $imagePath ) ) { return false; } } else { if( !@rename( $localPath, $imagePath ) ) { return false; } } $hash = md5_file( $imagePath ); $c = DB::query('SELECT id FROM '.TABLE_IMAGES.' WHERE hash = :1', $hash); if( !empty( $c ) ) { unlink( $imagePath ); $errors['duplicate'] = 'This image is already in our database!'; return false; } // make thumbs foreach( Config::$gridView['classes'] as $gc ) { $thumbPath = $thumbDir.'/'.$gc['dir'].'/'.$thumbName; Filesystem::mkdirr($thumbDir.'/'.$gc['dir']); if( !Image::createThumb( $imagePath, $thumbPath, $gc['width'] * Config::$gridView['gridSize'] - Config::$gridView['borderWidth'], $gc['height'] * Config::$gridView['gridSize'] - Config::$gridView['borderWidth'] )) { unlink( $imagePath ); $errors['internalError'] = 'Internal error processing the image!'; return false; } } $user->increaseScore( Config::$postScore ); DB::query( 'UPDATE '.TABLE_USERS.' SET images = images + 1 WHERE id = :1', $user->id ); DB::insertRow( TABLE_IMAGES, array( 'logged' => date('Y-m-d H:i:s', $time), 'user' => $user->id, 'score' => 3, 'votes' => 0, 'keyword' => date('Y/m/', $time).$keyword, 'tags' => $tags, 'image' => $name, 'thumb' => $thumbName, 'hash' => $hash, 'source' => $source ) ); $imageId = DB::insertId(); $colors = Image::getColors( $imagePath, 4 ); foreach( $colors as $c ) { DB::insertRow( TABLE_IMAGECOLORS, array( 'imageId' => $imageId, 'r' => $c['r'], 'g' => $c['g'], 'b' => $c['b'] ) ); } return true; } } ?> буду очень признателен если кто-нибудь подкинет идею
в дополнение могу сказать что интересует тот момент чтобы при выдаче пользователю изображение выдавалось с водным знаком и при сохранении тоже сохраняло водный знак, но на сервере оставалось без изменений так же мой скрипт после загрузки пользователем изображений создает миниатюры, водные знаки на миниатюре не нужны. интересует только полноразмерный вариант
посмотрите в сторону: Thumbnail and Watermark Class (by Emilio Rodriguez) я с его помощью в вешал водяные знаки на загружаемые фото в bitrix'е.