TCPDF Image doesnt show off normal - php

Im working on a PDF. I just wanted to change the logos so I changed the Image and on the first site I get the new image in correct size so but in the second pdf the image is very large.....
Here the line : $this->Image('images/logo.jpg', 160,12.0,30 );

I find it screws up if I used the same image twice. Best practise is to use an image only one time in a PDF. Make a copy of it under a different name if you are going to use it again.

Related

Image from database not appearing in same dimension as without database

I am making an e-commerce website in php with mysql database, I am using a web template for front-end, the issue is when I try to upload the image from database, it is not showing in proper dimension, however when i upload the same image without database it works and shows in proper size as defined in template. I don't know why is this happening because there are same css and same image class define for both.
Here is the screenshot of image in without database:
And below with fetching from database:
I am stuck how to make image display same as without database.
Simply add width and height to the image at front end and only retrieve image in src tag
This can fix your problem
& if it didn't fix please provide your code snap

How to convert image type using Wideimage library

I have a form where the user can upload an image and that image gets displayed on a webpage. I use the Wideimage library to resize the image and to rename the image. In the display code I have the name and type specified, but the problem is I don't know how to convert the image type in Wideimage so that it will display properly. I hope that makes sense.
Another option that would work is if I could somehow get the image type of the file name and then use that in the display code. I was looking at the php function getimagesize() but I couldn't quite get it working, that is, I had to run a bunch of if statements to see what type of image it was. It didn't seem practical.

Can I split an image to next page while displaying it on a pdf using fpdf library?

I am writing a code in php 5 to generate a pdf file which will have the images.I am displaying full length images.The image gets cut as soon as it reaches the end of the page(i.e. bottom of the pdf page).I want the image to continue being displayed from the next page.So that the complete images is visible even if it is larger than the size of the pdf page.Is it possible?If so please help!!
I'm not sure if it can be done using fdpf alone. The Image() function does not support partial images; so you need to find a way to split the image beforehand (using GD or something similar.)
In short, you need to find out how much of the image to print per page (ie. how high is the printable area of the PDF page, excluding header, footer etc.), and then create a temporary image consisting of the correct clipping of the image. This is what you add with the Image() function.
If using GD, here is how to copy a portion of an image into another image:
GD imagecopy() function

Can I un-cache one image? Or should I do things differently?

I allow users to add a profile picture of themselves to an account, pretty standard stuff.
To make things simple, when they update their image I simply overwrite the image they currently have stored (its not a big part of what we do so simple approach)
So, page is shown with their current image, they can then choose to upload a new one, the uploaded file is then saved, image URL updated in MySQL table and page is displayed again.
The image is uploaded correctly, MySQL table updated correctly, but the image is cached so old image shows on page even though they have uploaded a new one.
Can I un cache one image? Is there a better way to do this?
For avoiding image caching you can simply add a query sting in the image src. Best would be adding a date time.
{$t = getDate();}
and in your image src add: src= "path.jpg?t=".$t
For this you need not to change anything for new image..Date time automatically gets changed every second ;)
Hope it helps..
Use versioning. In the link for the image, instead of abc.jpg say abc.jpg?v=5. And when a new image is uploaded, change the number.
see this question

Add watermark to images

I've searched for ages for a solution, but I can't really find the solution to fit my needs.
So here's the story. Im creating a website and I really want to add watermarks to the downloaded images.
Yesterday I was browsing in a website called 9gag. If you haven't heard this website before, its a comic based website, and I found out that when you download an image, or access an image from anywhere else except their website, there's a 'watermark/banner' at the bottom of the image.
For example take this image:
link , notice no banner at the bottom of the image.
If you right-click, 'Copy image URL' , you get this link: image . See the banner now?
Im very confused on how they do it, and it would be great if we could use this on our websites.
Anyone with any ideas? Is it using any type of CGI?
P.S: I Wasn't sure what tags to add, So if anyone knows a better tag combination, please do edit it.
This effect is just a css trick. The image itself actually contains the watermark at the bottom, but the image tag is wrapped in a block that hides (overflow:hidden) the bottom 42 pixels of the image when it's being displayed in the page.
There are other things you can do that are more sophisticated (for instance, have the image served via a php script and comparing the http referer
header("content-type: image/jpeg");
if (!isset($_SERVER['HTTP_REFERER'])){die("alert('Restricted Access!');");};
$_u=parse_url($_SERVER['HTTP_REFERER']);
$_u=preg_replace("/(www.)/i","",strtolower($_u['host']));
$_i=$_SERVER['HTTP_HOST'];
$_i=preg_replace("/(www.)/i","",strtolower($_i));
if ($_u != $_i){
//handle this with gd or redirect
}
) but this will only work if someone tries to load the image from a different website or if they go to the image url... generally save-as will save the image from the browser's cache, so the css trick might be the best option you have (or a combination of these options). Fundamentally keep in mind that anything you show on the web can be captured (the code above isn't foolproof, and you can always prtsc).
GD library of php will help you doing that.
You'll need to create a new image using imagecreate function but adding some more "space" to the original size. Example: if I have an image of 200x200 (which you can retrieve using gd functions too) you'll need to create a 200x220px image using that function
Fill the new image with that gray color using imagefilledrectangle function
Copy the original image into the new one using imagecopy
Set the header's content type to image/type png gif etc..
Output to the image using imagepng or any other function that has the format you want.
I've had success with JQuery Watermark:
Jquery Watermark

Categories