The mPDF does not display images with spaces in the path - image

I am using MODX.
For example, image with path assets/modules/ZipUpload/Jemchug/mini_820094.jpg displays correctly, but assets/modules/ZipUpload/Duplicate of Kulonyi, Podvesyi/mini_820022.jpg does not.

In the AdjustHTML function of the mpdf.php file there is a line that causes this problem with images:
$html = preg_replace("/[ ]+/",' ',$html);

Related

Show images inside a pdf created with Gloogle Apps Script Blob

I am creating PDF files using blobs in Google Apps Script from a HTML code, but the problem is that HTML code has an image (referenced by "http") but the created pdf can't show it.
This is my code
function createBlobPDF(myMessage,myTitle){
var blobHTML = Utilities.newBlob(myMessage, "text/html", myTitle+ ".html");
var myPDF = blobHTML.getAs("application/pdf");
return myPDF;
}
Any solution? thanks!!
If the images in HTML are loaded from URLs, the converted PDF file doesn't include the images. If you want to include the images in the converted PDF file, please put the images to HTML as base64 data.
In order to confirm this situation, please see the following sample script. This sample script puts an image as URL and base64 data. The result is displayed them to a dialog and created a PDF file.
When you use this script, please copy and paste to the script editor of Spreadsheet.
Sample script :
function myFunction() {
// image
var url = "https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a";
var blob = UrlFetchApp.fetch(url).getBlob();
var b64 = blob.getContentType() + ';base64,'+ Utilities.base64Encode(blob.getBytes());
var html = "URL<img src=\"" + url + "\">Base64<img src=\"data:" + b64 + "\">";
var h = HtmlService.createHtmlOutput(html);
// Open dialog with the images.
SpreadsheetApp.getUi().showModalDialog(h.setWidth(500).setHeight(200), 'Sample');
// Create from HTML to PDF file.
DriveApp.createFile(h.getAs("application/pdf").setName("text.pdf"));
}
Result of dialog :
Both images can be seen.
Result of PDF file :
Only the image of base64 can be seen.
Note :
This is a simple script. So please modify this to your environment.
References :
How to display Base64 images in HTML?
If I misunderstand your question, I'm sorry.
I tested converting html to pdf with image content. It works but in the bottom of a box, the color does not work! How to make the color to appear in the background of a box?
I wanted to show you my little treatment as an example "<>" but it doesn't work because there is no window for code.gs . Shame...
In short, see the final result in pdf, attached
before clicking on the "validate" button, the screen is displayed, see the screenshot below. this is where you "capture" the HTML presentation and then run to convert HTML to PDF.
after clicking on "validate", here is the result, see below :
normally, I would like to have the same result between screen and PDF.
Then, how to do it ?

How to get original size of image in imageFallback Magento?

How to get the original size of image in imageFallback? I used the below code to get the images.
My code:
echo $imageFallback['image_fallback'];
Return:
http:\/\/www.xxxxxx.com\/media\/catalog\/product\/cache\/6\/image\/500x800\/602f0fa2c1f0d1b8sa098a09s9856ff9\/c\/o\/car1.png
But i need return the original file, without resize:
Ex:
http:\/\/www.xxxxxx.com\/media\/catalog\/product\/c\/o\/car1.png
Thank you

Ruby Watir-webdriver saving image when navigating directly to the image

I'm trying to grab a set of information from a series of pages that are loaded via JS and to accomplish that I'm using watir-webdriver to load the page and nokogiri to parse them. This is working great, however, I need to grab a picture off of the page. The path of the picture is generated upon the page's loading so I wrote the following to create an array of relative URLS to the images and navigate directly to the absolute URL of the first index of the array, which is always the image I want.
img_srcs = $page_html.css('img').map{ |i| i['src'] } #genereates an array of relative urls pointing to every image
imageURL= "website.com" + img_srcs[1].gsub("..","").to_s #take the relative URL of image at index position 1 (the image) and converts it to an absolute URL
$browser.goto(imageURL)
How can I save this image which the browser has directly loaded? Any help would be appreciated and please let me know if I anything is unclear.
Edit:
I've now added the following code
image_source = $browser.image(:class => "decoded").image.src
File.open("#{$imageID}.txt", "w") do |f|
f.write open(image_source).read
f.close
end
However, I'm getting the error
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir-webdriver/el
ements/element.rb:490:in 'assert_exists': unable to locate element, using {:tag_
name=>"img"} (Watir::Exception::UnknownObjectException)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir
-webdriver/attribute_helper.rb:71:in 'block in define_string_attribute'
from 12.rb:121:in 'imageDownload'
from 12.rb:134:in 'navAndGrab'
from 12.rb:137:in '<main>'
When you do:
$browser.image(:class => "decoded").image.src
You are looking for the html:
<img class="decoded">
<img src="what_you_want"></img>
</img>
I am guessing your html is not like that, hence you get the exception regarding finding the image within the image.
You probably just want the first image with class decoded (remove the second .image):
image_source = $browser.image(:class => "decoded").src
Or maybe you want the full list of images and then get the first one:
image_source = $browser.images(:class => "decoded").first.src

Showing a default Image in a CakePHP application

I am working in a CakePHP application, where I am using HTML helper's image() function to show images. What I want, if it gets the image in the given path, then it will show the image, otherwise, it'll show a default image. I have that "default" image, but I don't understand where/how to define it.
Thanks
Extend the HTML helper and add the logic to the image method and override the called image with your default image if the originally requested image does not exist.
index.ctp file code
<?php
$MyImage = $post['Post']['image0']; // image0 is my db field
if (file_exists("img/uploads/posts/".$MyImage))
$MyImage1 ="/img/uploads/posts/".$MyImage;
else
$MyImage1 = "/img/uploads/posts/no-image.jpg";
echo $this->Html->image($MyImage1);
?>
Note : My post's images are stored in app/webroot/img/posts folder(default image is also in this folder.)

Image issue inside PDF loop

I'm using DOMPDF to generate PDF's that can contain images and I'm having a weird issue with that.
The PDF is generated inside a loop and the amount of PDF's that needs to be generated varies. When there is only 1 PDF generated everything goes well. The image (or logo in this case) is getting inserted beautifully.
But when there are 2 or more PDF's that have to be generated for some reason the image is replaced with a red cross. But: the image in the first PDF generated in that batch works perfectly. So: the image in PDF #1 loads perfectly, the image in PDF #2 and up is getting replaced with a red cross.
I'm using the latest stable release of DOMPDF (v0.5.2). I've also tested with v0.5.1 but that had the same behaviour.
The server I'm testing this on runs on Linux, with PHP 5.3.8. No errors in the error-log about this (and I do have error logging enabled).
--- edit:
The "path" to the image is an absolute URL, not an absolute or relative (PHP) path and with outputting the contents of the loop to the browser (or a normal HTML email, without the PDF attachment) it displays the image (in all mails) perfectly.
--- edit2:
Using a function to flush all buffers at the end of the loop (which, unfortunately, doesn't change anything to my issue):
function flush_buffers()
{
ob_end_flush();
ob_flush();
flush();
ob_start();
}
An example of the loop I'm using:
for ( $i = 0; $i < count($cert); ++$i )
{
// load the email-template
ob_start();
include($template);
$content = ob_get_contents();
ob_end_clean();
// require dompdf
include_once('dompdf/dompdf_config.inc.php');
// set PDF path - inside temp dir
$newpdf = trailingslashit(realpath(sys_get_temp_dir())).$cert[$i]['coupon'].'.pdf';
// replace shortcodes with wanted content
$certificate = preg_replace($shortcodes, $replacements, $certificate);
$certificate = '<html><body>'.$certificate.'</body></html>'."\n";
$dompdf = new DOMPDF();
$dompdf->load_html($certificate);
$dompdf->set_paper($pageformat, $orientation);
$dompdf->render();
save_pdf($newpdf, $dompdf->output()); // save PDF
#flush_buffers();
}
One of the shortcodes is [logo] and that's getting replaced with an img-tag. As I previously mentioned: that image works fine in the first PDF, but not in the other PDF's.
Upgrading to dompdf 0.6beta2 fixed this issue. Thanks Fabien!

Resources