How to add watermark Image using MPDF in codeigniter - php

here is the pdf image
I want to add this kind of background image to my PDF using MPDF. But also i want to reduce the background image opacity.

Try this-
$mpdf->SetWatermarkImage(
'assets/dist/img/ExampleLogo1.png',
0.3, // this for transparency
array(x,y), // Alignment
);

Related

Font color not change in php intervention image manipulation

I'm using PHP Intervention Image Library 2.x to put some text on an image. Everything works fine except for the font colour.
Font size, font, font angle, and the position change according to the given values, the only issue is it not takes the colour I'm setting in the callback function.
Image::configure(array('driver' => 'imagick'));
$img = Image::make(IMG . 'gold-full.jpg');
$font = new Intervention\Image\Imagick\Font();
$img->text('Y. C. Perera', 1061, 1298.4, function($font) {
$font->file('./img/ERASBD.TTF');
$font->size(88);
//$font->color('#fff');
//$font->color('white');
//$font->color(array(255,255,255));
$font->color('#ffffff');
});
$img->save('./uploads/new-gold-full.jpg');
$img->destroy();
As I mentioned with the comment I tried all those types of settings for the color. but no luck.

png with transparency and png-derived blob are rendering black on canvas element instead of transparent

I am letting users preview images using URL.createObjectURL() (which represents the image as a blob). This has worked great, but now I am using the plugin jCrop to let users crop said images and I have encountered a minor issue.
jCrop has worked fine for blobs derived from jpg files and png files w/o transparency, but blobs derived from png files with transparency are rendering transparent pixels (on the canvas) as black (the same effect was happening with these images when resized and uploaded to the backend (php) but this was corrected using imagealphablending()).
jCrop is called as followed:
jQuery(function($) {
$("#myImageContainer").Jcrop({
onChange: myFunction
}, function () {
jcrop_api = this;
});
});
The "black" images on canvas are uploaded and saved properly with transparency, so this is a front end effect only. Additionally, the same effect is observed when the source png is used to preview instead of the png-derived blob. Is their any way to correct for this effect on the canvas instead of the backend?
UPDATE: The transparent image is black from the start...I am assuming the author of the plugin set the canvas background to be black. I will try and change this.

CROP IMAGE IN FPDF is possible?

May i crop images in FPDF ?
i have try this one Cropping images in CodeIgniter for FPDF output but does not work
You can use clipping areas: http://www.fpdf.org/en/script/script78.php
With this extension you can define your visible area and output your image like this:
$pdf->ClippingRect($x, $y, $w, $h);
$pdf->Image($imageFile, $x - $imgOffsetX, $y - $imgOffsetY);
$pdf->UnsetClipping();
The whole image will be included in the pdf. If size matters, cropping the image file first can be the better way.
Sorry, you can not crop an image in FPDF. You must first crop the image before using it to create a PDF using FPDF. I can recommend doing this manually, or programmatically via ImageMagick. Then once you have your cropped jpg, gif or png, call Image.
$pdf->Image('croppedImage.png');

How to make image's background transparency to 0?

There are images displayed inside a HTML table in a PHP code :
The code of this table is :
for ($i = 0; $i < $data['list']['cnt']; $i++) {
$tabRows[$i][1]['width'] = "45%";
$tabRows[$i][1]['align'] = "center";
$tabRows[$i][1]['value'] = '<img src="'.HTTP_FIGURES.$data['list'][$i]['fig_image'].'" />';
}
As you can see the background of the images are seen and they make the page dirty. So I want to remove the background of each image. How to do that ?
Make the images a transparent PNG.
Your only practical solution is to go through each image with an image editor, delete the background and re-save as a .png with transparency.
Take any image editor like GIMP (free), Paint.net(free), Photoshop or any other image editor and add transparency where you need it. Here is a tutorial for paint.net. If your images are not in PNG - you will need to make PNG images as JPEG has no transparency.
You have 2 options:
Edit images with a image editor like paint.net and make the backgrounds transparent.
Use the PHP GD functions to 'edit' the images. This can be cumbersome, because you have to determine what color you want to replace with a background color. Often, a fixed color is used, or the color in pixel[1,1].
My advise, if there are not to many images, go for 1.

Print stylish text on image in php

Is it possible to print html div tag with style on image in PHP?. if not, then what is the alternative way?
Some hosts have ImageMagick for PHP. To add text to your image, take a look at the syntax of the commands here. The example given on that page should help some - it's pretty easy to get text on an image.
The benefits of using ImageMagick over a fixed image is that you can vary the content of the text, which is what you might want (you didn't mention needing a static text; for this, I'd use an image with a transparent background). For more comprehensive font commands, take a look here.
To put a transparent image on top of your base image, take a look at this very nicely designed site.
I'll also give the code presented on that site here:
$photo = imagecreatefromjpeg("original.jpg");
$watermark = imagecreatefrompng("watermark.png");
// 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);
To output the image to a file, please Google that and replace the last two lines of the example given above.
For ImageMagick stuff, take a look here
I hope this helps :-)
James
You can set the image as the background graphic of any div using CSS. Then the text within that div will appear on top of the image.
(CSS)
.mydiv {
background:url(/path/to/image.gif);
width:100px; /* set to width of the image */
height:100px; /* set to height of the image */
}
(HTML)
<div class='mydiv'>Some text here</div>
There is no easy way to print text on images using html/css on server side, because php can't parse html, so you'd better find another solution like php GD.

Categories