How to Add Watermark on a Exist Image

How to add watermarks on an image in iphone

Just add image on your image view and then add one subview on it and set alpha of subview less so it look like water mark or you can add label, but in label you have to change its angel to show angular

Adding watermark on image from databases in Laravel 5.3

public function getFilePathAttribute($value){
$img = Image::make(public_path($value)); //your image I assume you have in public directory
$img->insert(public_path('watermark.png'), 'bottom-right', 10, 10); //insert watermark in (also from public_directory)
$img->save(public_path($value)); //save created image (will override old image)
return $value; //return value
}

It is better to do it on upload so you do it Once not always when trying to access the image path from DB (less proccess) FYI: this will save already watermarked image

add watermark image to uploaded image

I tested this using the code below and this worked ok. Obviously I have used paths relevant to my test system but hopefully it should help.

One of the most important and often forgotten things when uploading and dealing with uploaded files is the enctype of the form - so I included my test form as an example.

If you want to save the image as well as display it with the watermark use the imagepng function twice, once with a filename and the other without.

<form method='post' action='/test/so/wtrmarkimg.php' enctype='multipart/form-data'>
<h1>Image uploader - Watermark</h1>
<input type='file' name='image' />
<input type='submit' value='Submit' />
</form>

<?php

#$path = "../large/";

$path='c:/temp/';/* output path for images generated */
$watermarksrc=realpath( 'c:/wwwroot/images/watermark.png' );

if( isset( $_FILES['image'] ) ){

$img_tmpname=$_FILES['image']['tmp_name'];

$num = substr( md5( mt_rand( 1,9999999999 ) ),0,9);
$new_name = $path.$num.".jpg";
$image = $num.".jpg";

if( move_uploaded_file( $img_tmpname, $new_name ) ){

$image = imagecreatefromjpeg( $new_name );
$logoImage = imagecreatefrompng( $watermarksrc );
imagealphablending( $logoImage, true );

$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$logoWidth=imagesx($logoImage);
$logoHeight=imagesy($logoImage);

imagecopy(
$image,
$logoImage,
$imageWidth-$logoWidth, $imageHeight-$logoHeight,
0, 0,
$logoWidth, $logoHeight );

// Set type of image and send the output
header("Content-type: image/png");
imagepng( $image );/*display image with watermark */
@imagepng( $image, $new_name );/* save image with watermark */

// Release memory
imagedestroy( $image );
imagedestroy( $imageLogo );
}
} else {
echo "ERROR";
print_r($_FILES);
}
?>

PHP watermarking

replacing imagecopymerge with imagecopy solved the issue. here is the new code

function watermark($image){
$overlay = '../../../photos/photosets/stamp.png';
$opacity = "20";
if (!file_exists($image)) {
die("Image does not exist.");
}
// Set offset from bottom-right corner
$w_offset = 0;
$h_offset = 100;
$extension = strtolower(substr($image, strrpos($image, ".") + 1));
// Load image from file
switch ($extension)
{
case 'jpg':
$background = imagecreatefromjpeg($image);
break;
case 'jpeg':
$background = imagecreatefromjpeg($image);
break;
case 'png':
$background = imagecreatefrompng($image);
break;
case 'gif':
$background = imagecreatefromgif($image);
break;
default:
die("Image is of unsupported type.");
}
// Find base image size
$swidth = imagesx($background);
$sheight = imagesy($background);
// Turn on alpha blending
imagealphablending($background, true);
// Create overlay image
//$overlay = imagecreatefrompng($overlay);
// Get the size of overlay
$owidth = imagesx($overlay);
$oheight = imagesy($overlay);

$photo = imagecreatefromjpeg($image);
$watermark = imagecreatefrompng($overlay);
// This is the key. Without ImageAlphaBlending on, the PNG won't render correctly.
imagealphablending($photo, true);
// Copy the watermark onto the master, $offset px from the bottom right corner.
$offset = 10;
imagecopy($photo, $watermark, imagesx($photo) - imagesx($watermark) - $offset, imagesy($photo) - imagesy($watermark) - $offset, 0, 0, imagesx($watermark), imagesy($watermark));
// Output to the browser
header("Content-Type: image/jpeg");
imagejpeg($photo,$image);
// Overlay watermark
// Destroy the images
imagedestroy($background);
imagedestroy($overlay);
}

How might I add a watermark effect to an image in Android?

I found great tutorial on Android Image Processing here.

public static Bitmap mark(Bitmap src, String watermark, Point location, Color color, int alpha, int size, boolean underline) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());

Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);

Paint paint = new Paint();
paint.setColor(color);
paint.setAlpha(alpha);
paint.setTextSize(size);
paint.setAntiAlias(true);
paint.setUnderlineText(underline);
canvas.drawText(watermark, location.x, location.y, paint);

return result;
}

Thanks to Pete Houston who shares such useful tutorial on basic image processing.

Add watermark image in android

it solved , I just change little for that code , and thanks for ur advice Doomsknight :)

 public static Bitmap mark(Bitmap src, String watermark) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setTextSize(18);
paint.setAntiAlias(true);
paint.setUnderlineText(true);
canvas.drawText(watermark, 20, 25, paint);

return result;
}

and I call with this function

bitmap = mark(bitmap, "Hallo");
imgshoot.setImageBitmap(bitmap);


Related Topics



Leave a reply



Submit