Hello. I am new to Drupal. I have a created a custom content type that has a field to attach an image (field type is Image). I would like to display PDF and TIF files as images (the same way a JPG would show up).
When I try to upload a PDF in the image upload field it says: "The selected file File.pdf cannot not be uploaded. Only files with the following extensions are allowed: jpg, jpeg, png, gif, tif."
So I figured at least I could upload a .TIF. Then when I try to upload a .TIF it says: "The selected file File.tif could not be uploaded. Only JPEG, PNG and GIF images are allowed."
Can anyone share some info on whether there is a way to upload a .TIF file (or PDF file) as an image?
Thanks very much.
Comments
Comment #1
yched commentedThis is a request for imagefield module, not for drupal core. The 'felld system' doesn't exist in core Drupal 6, it is work in progress for the future drupal 7.
Also not that I don't think you'll be able to display a pdf as an image, and I don't think many browser support tif images.
Comment #2
quicksketchyched is right, you'll need to do some kind of crazy conversion to have TIF and PDF files uploaded then displayed as an image. You can use a FileField instead of an ImageField to actually upload the file. ImageField needs to generate previews of the uploaded files, but since most servers don't support TIF images, it's not a supported option in ImageField.
So, assuming you switch your field to use a "File" upload instead of an "Image", you can now upload any file type you want. To actually make PDFs or TIFs output as an image in the broswer, you'll need to have ImageMagick installed on your server (the built-in PHP library GD cannot read PDF files). Then you can setup ImageCache to do a file conversion to a standard format such as PNG or JPG.
Comment #3
zmetzner commentedThank you very much for the information. I will look into doing the file conversion with ImageCache.
Comment #4
egfrith commentedI'm new to imagecache, but having spent an hour or so looking at the code, it's not clear how the conversion would be done without hacking the imagecache code itself. All of the below is an experiment with the code rather than a concrete proposal for modifying the code.
Let's say I want to get a preview of:
http://example.com/files/imagecache/Original/files/test_file.pdf
This $path is passed to _imagecache_cache(), and is tested to see if it's an image using getimagesize(). _imagecache_cache() exits if the file at $path isn't an image. This can be hacked around by replacing the getimagesize() test with something like this:
The next modification which actually allows conversion from pdf to jpg (and hence viewing in a browser) is to replace pdf with jpg in the path of the destination file:
I've also modified added a '[0]' to the imageapi function _imageapi_imagemagick_convert() so that multipage pdf documents might work:
Put together this is beginning to work. But before I fiddle around with it more (and perhaps produce a patch) I'd like to know if this is the right way to go about things, or if it is possible to use an actions plugin somehow.
Comment #5
quicksketchYes I should have mentioned you should use the ImageCache Actions module, which provides the option "Save as different format". Then as the last action in a series, you can convert the format to JPG or PNG.
Comment #6
egfrith commentedThanks for the quick response. Using imagecache_actions would probably work for .tif files (which was the original question in this thread) but I don't think it will work for .pdf files, because _imagecache_cache() bails if the requested file isn't an image before calling imagecache_build_derivative().
So I still think that to derive images from PDFs there needs to be some sort of modification to imagecache.module.
One option could be to convert the PDF file to an image format, store this in a temporary directory and set $src to the location of the converted file. This would happen in _imagecache_cache() before the getimagesize() test, perhaps with a function call like this:
_imagecache_convert_to_image_format() could be extended, perhaps via conversion actions/plugins to convert other file types (e.g. ps, eps, openoffice) to image formats (e.g. png or jpg).
Would you be interested in adding this sort of functionality to imagecache? If so I could try to work on a patch.
There might be a danger of duplicating some of the functionality of http://drupal.org/project/fileframework . That said, the file framework module is quite large and appears to do considerably more than I need at present.
Comment #7
drewish commentedi'd be interested in adding functionality to imageapi to determine if a file is an image... basically replicating image_get_info() at the toolkit level so that imagemagic could determine that pdf's are valid images, etc. then imagecache would have something more intelligent to base it's resizing off of.
Comment #8
egfrith commentedImproved functionality in imageapi to determine if a file is an image sounds like a good idea. In principle I'd be happy to work on it, but I probably won't have time to do so for a week or so.
The improved functionality would appear to be related to the patches to image.inc, image.imagemagick.inc and image.module:
#269327: Support for more image types (PDF, TIFF, EPS, etc.)
#269329: ImageMagick support for more image types
#269337: Support for more image types (PDF, TIFF, EPS, etc.)
I'm guessing that now imageapi is in (or heading for) core, these patches need significant reworking.
I'm wondering where the best place to work on a patch to imageapi is (if/when I get the time): one of the existing patches above, or as a new issue in imageapi 6.x or in core?
If this work is done it might also address #366373: PDF support ( i.e. convert PDF to JPG support)
Comment #9
egfrith commentedAs a place to work on imageapi_image_get_info(), I have created #416254: Add equivalent of image_get_info() at the toolkit level.
Comment #10
quicksketchAs a support request, this issue is fixed. If wanting to have this feature, please open a new issue (reference this one if possible) when the ability to support TIF options becomes viable through ImageAPI or core.
Comment #12
Alex Andrascu commentedI didn't understand from the previous posts wether imagefield does/will suport tiff. Please let me know if there are any relevant new topics opened on this subject. Thanks in advance
.