DOMPDF - background url (linux vs windows) - php

When I generate PDF from html, my img doesn't show on server linux.
In Localhost, my image is getting displayed.
my code css :
background: red url("<?php echo __DIR__ ?/my_img.png");
But on server linux, it's not getting displayed
For Info :
If I write
<img src="<?php echo __DIR__ ?/my_img.png">
I see this image on both server.
EDIT :
I need to repeat image (x and y)
So I don't insert a
I try this
.myimg:after {
background: red url("<?php echo __DIR__ ?/my_img.png");
}
But IMG is not getting displayed.
So I think DOMPDF can't interpret URL in background in CSS.
An idea?

I find :
<img src='data:image/png;base64,<?php echo base64_encode(file_get_contents("myimg.png")); ?>'>
Its works!

Related

mPDF: image in CSS

I'm using mPDF to generate PDF's on my website.
In my CSS I use to have a image as background:
.page{
height:297mm;
width:210mm;
background:url(../bookletFiles/exam_header.png) no-repeat scroll;
padding:400px 1.6cm 1.7cm 1.6cm;
}
This has been working for a long time. But lately I noticed that, when I declare $mPDF->debug to true, I receive the following error:
<B>mPDF error: </B>IMAGE Error (http://topografieindeklas.nl/wp-content/themes/topografieindeklas/bookletFiles/exam_header.png): Could not find image file
Strangley, when I remove the CSS declaration and use the exact same image in tag's, it is displayed.
I already tried to regenerate the .png file, replace it with a .jpg file but this hasn't had any result.
The only thing I can image that has changed lately, is an upgrade from PHP 5.3 to 5.4 The allow_url_fopen settings is set to true though.
Does anyone has any thoughts on why this image won't load through CSS and how that could be fixed?
Try this in the view of your pdf file.
<?php $dir= $this->webroot."img/cake.icon.png"; ?>
<?php echo $dir; ?>
<img src="<?php echo $dir; ?>">

Imagick is displaying blank images with php

I installed imagick and checked to make sure the class exists etc. I can get it to count images in tiffs and other things. However, I cant get it to display an image. I am using the following code :
header('Content-type: image/JPG');
$image = new Imagick(' ur to my jpg here ');
$image->thumbnailImage(100, 100);
echo $image;
But it displalys a blank image. When I look at the HTML code produced I get this:
<html>
<body style="margin: 0px;">
<img style="-webkit-user-select: none" src=" url to this page imagechange.php">
</body>
</html>
Can anyone explain why the image is not being displayed? Above the HTML appears the image src as the PHP page that I am using and not the image.

Strange black line under Wordpress logo

I am building my own website using Wordpress. When I was using a PNG picture(140*82 px) instead of the default "site-title" as my site logo, I got a really strange result. The picture is presented nicely, but there is a black line just under the picture. I have checked my "header.php" and "style.css" file, nothing wrong there. I also used Chrome "Inspector" to check the logo, it said: img 140*83( natural 140*82 ).
So, where does this line come from? Thanks, guys!
Here is my logo section in "header.php":
<<?php echo $heading_tag; ?> id="site-title">
<span>
<img src="http://118.228.173.234/wp-content/uploads/logo.png" width = "140" height = "82">
</span>
</<?php echo $heading_tag; ?>>
It's gotta be CSS related then. Check if you have reference to span in your CSS and locate the black #000 or #000000. Hard to tell without seeing more code at this point. Check for #site-title in CSS also.

li cannot find image

I have an ul with a li that cannot find a .PNG image associated with the list item 'li' in the code here:
$pngFilename= 'C:/xampp/htdocs/myProj/' . 'just_a.png';
echo 'pngFilename is "', $pngFilename, '" -- that was the .png image filename.';
// within a 'ul' is this li item that displays an image (the ul code is simplified
// to only show the item that (needs to but doesn't!) display a .PNG image.)
echo '<ul>';
echo '<li>';
echo '<a href="http://localhost/myProj/just_an.htm">';
echo '<img src="', $pngFilename, '"';
echo 'alt="http://localhost/myProj/the_other.png"';
// NOTE -- I left out the close /> to the img statement when I copied my code here but
// it was in fact in my source code.
echo '/>';
echo '</a>';
echo '</li>';
echo '</ul>';
Before I wrote the above php code, I tested just the raw html and it was fine -- my .PNG file called
C:/xampp/htdocs/myProj/just_a.png was displayed correctly.
But when I switched to php server-side generation of the html, the C:/xampp/htdocs/myProj/just_a.png image does not appear, only the 'cant find it' default small image appears that looks like a piece of paper torn horizontally.
Any ideas? The .png file exists and so does the directory and the html correctly displayed the image, but when I put the html into php 'echo' calls I must be screwing something up, just not sure what.
To make sure I have the correct path and filename you'll see I echo it out at the top of the code.
The php variable $pngFilename is displayed when I do 'View Source' in the browser as:
pngFilename is "C:/xampp/htdocs/myProj/just_a.png" -- that was the .png image filename.
The only other thing to mention is that the 'alt' link, the 'alt="http://localhost/myProj/the_other.png"' -- this link (not the image) shows as blue underlined link text.
Why did this work in my html but breaks when I use the 'echo' in php? After all, the 'echo' simply sends the html to the client side -- and that .png file is 100% definitely there and displays fine when I run the above html outside of php's "echo" command.
This is because the path to the image changes depending on how your viewing the page. in a local context or from a server context; and since you are using an absolute path instead of a Relative path the system can't adjust for the change in the location of the image. Unlike when using a PHP function that calls on the php file system functions that do use the internal file system. what your doing is having it send a text file to the browser which isn't rendered as HTML code until after PHP has finished. because of that it has no access to the php file system to resolve the path to the image on the server. the way to fix it would be to use the path to the image Relative to the PHP script or use the web accessible path to the image
$pngFilename= 'C:/xampp/htdocs/myProj/' . 'just_a.png';
Should for example be
$pngFilename= 'http://localhost/myProj/' . 'just_a.png';
or if the image and the php file are in the same directory you could just do
$pngFilename= 'just_a.png';
You should try to close your img tag:
echo '<img src="', $pngFilename, '"';
echo 'alt="http://localhost/myProj/the_other.png">';
You are generating a image tag like:
<img src="C:/xampp/htdocs/myProj/just_a.png" alt="http://localhost/myProj/the_other.png" />
You cannot use this path, you need to change it to http://localhost/myProj/just_a.png or something like file:///C:/xampp/htdocs/myProj/just_a.png.

Can I embed a .png image into an HTML page?

How can I embed a .png file into a blank "file.html" so that when you open that file in any browser you see that image?
In this scenario, the image file is not linked to from the HTML, but rather the image data is embedded in the HTML itself.
There are a few Base64 encoders online to help you with this, and this is probably the best I've seen:
http://www.greywyvern.com/code/php/binary2base64
As that page shows your main options for this are CSS:
div.image {
width:100px;
height:100px;
background-image:url(data:image/png;base64,iVBORwA<MoreBase64SringHere>);
}
Or the <img> tag itself, like this:
<img alt="My Image" src="data:image/png;base64,iVBORwA<MoreBase64SringHere>" />
The 64base method works for large images as well. I use that method to embed all the images into my website, and it works every time. I've done it with files up to 2 MB size, JPEG and PNG.
I stumbled upon similar problem now and the solution is:
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use GD::Graph::pie;
use MIME::Base64;
my #data = (['A','O','S','I'],[3,16,12,47]);
my $mygraph = GD::Graph::pie->new(200, 200);
my $myimage = $mygraph->plot(\#data)->png;
print <<end_html;
<html><head><title>Current Stats</title></head>
<body>
<p align="center">
<img src="data:image/png;base64,
end_html
print encode_base64($myimage);
print <<end_html;
" style="width: 888px; height: 598px; border-width: 2px; border-style: solid;" /></p>
</body>
</html>
end_html
You can embed images using the methods listed in other answers, such as in HTML
<img alt="My Image" src="data:image/png;base64,base64-data-goes-here" />
or CSS
div#my-image {
width:150px;
height:100px;
background-image:url(data:image/png;base64,base64-data-goes-here);
}
For Base64 encoding, on Linux I use the standard base64 tool with wrapping turned off, like this:
base64 -w 0 my-image.png
and copy/paste the output text verbatim.
A quick Google search says you can embed it like this:
<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7"
width="16" height="14" alt="embedded folder icon">
But you need a different implementation in Internet Explorer.
http://www.websiteoptimization.com/speed/tweak/inline-images/
Use mod_rewrite to redirect the call to file.html to image.png without the URL changing for the user.
Have you tried just renaming the image.png file to file.html? I think most browser take mime header over file extension :)
You can embed a png image like you can embed jpg images or any type of images in html from your device or from the web .
Be sure that the type of the image is png when you are saving it on your device.This is the same way but I embed it as jpg.
<embed type="image/jpg" src="https://s3-us-west-2.amazonaws.com/textimgs/music/250px-Antonio_Vivaldi.jpg" width="500" height="500">
</EMBED>
I want to say thanks to Stack Overflow that let us ask and answer!!!!!!!!!!!!!!!!

Categories