Missing image files

vomc8one - June 28, 2007 - 23:41
Project:Pdfview
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Not sure if this is a deep bug or not but I am having trouble printing images with pdfview. I have this set up with php 5.22 and allow_url_fopen = On. I noticed that any images that include spaces in their (%20) tend to cause problems IF they are in blog postings. So for example a post that includes an image at

/files/images/greenhpdesktop.preview.jpg

works fine. But if the images contain spaces, then I get this:

TCPDF error: Missing or incorrect image file: files/images/25%20KW%20CPV%20by%20Amonix.preview.jpg

Interestingly I get these errors even though those images are accessible through the URL path provided. So I can display
http://example.com/files/images/25%20KW%20CPV%20by%20Amonix.preview.jpg in my browser without a problem.

When I create a page posting into which I hardcode the image URLs as src=images/25%20KW%20CPV%20by%20Amonix.preview.jpg then they also show up fine as a PDF...

Any ideas? I haven't taken a close look at the code yet, but it seems that mainly base_url and leading slashes are stripped... So I don't fully understand why I am having these issues...

Any help would be appreciated before I start hacking into here...

Another tid-bit that I noticed is that base_url is usually stripped but if the image path includes a 'www' in front of the base_url then that is not cut off in _pdfview_rewrite_image_url

Thanks
- jochen

#1

vomc8one - June 29, 2007 - 01:17

correction: when i create the page content my embedded link is:

sorry for any confusion.

#2

vomc8one - June 29, 2007 - 01:21

woops, should have used the code tags for that:

the image link in the page posting is:

img src=images/25%20KW%20CPV%20by%20Amonix.preview.jpg

#3

vomc8one - June 29, 2007 - 02:10

OK i did more digging and i think i am close. I am using pdfview to create PDFs of blog entries. Images are the problem. Images are added using img_assist which makes things easier for non-html people. It seems that img_assist inserts the IMG tag as

Sky%20stream.6.thumbnail.jpg

which of course results in an error from TCPDF:
TCPDF error: Missing or incorrect image file: files/images/Sky%20stream.6.thumbnail.jpg

Now, if I go and change the posting, removing the %20 and leaving the HTML source as:

<img class="image thumbnail" src="/files/images/Sky stream.6.thumbnail.jpg" width="100" height="96" />

then it works...

So I don't know, I guess I can urldecode these image names but I worry that that may break something somewhere. Is this something that I should change in the img_assist module?

- j

#4

vomc8one - June 29, 2007 - 02:32

So for now I just added the following three lines into the _pdfview_rewrite_image_url function. I would be interested in any feedback on this hack. Part of me is not sure whether this is the best way to deal with this issue:

  //hack at around line 278 -> strip url characters in image_names
  $img_name = substr(strrchr($path, '/'), 1);
  $rest = substr($path, 0, (strlen($path) - strlen($img_name)));
  $path = $rest . urldecode($img_name);

I guess that could all be compressed into one elegant and somewhat cryptic line of php...

thanks
- j

#5

vomc8one - July 5, 2007 - 14:24

  //hack at around line 278 -> strip url characters in image_names
 
$img_name = substr(strrchr($path, '/'), 1);
//woops, had to modify this 
$rest = substr($path, 0, (strlen(urldecode($path)) - strlen($img_name)));
  $path = $rest . urldecode($img_name);

#6

sun - October 3, 2007 - 19:09

This is a Drupal core issue. You definitely should test Transliterate filenames module. Please report back if that module works for you (and mark this issue fixed if it does).

 
 

Drupal is a registered trademark of Dries Buytaert.