I am using _imagemagick_convert directly from an image style custom action to convert pdfs to jpgs. I cannot get it to work as the destination is always cleared when looking at the imagemagick debug output.

The problem is caused by drupal_realpath($dest) which returns an empty string if the file $dest does not exist. Since this is the image to be created it is very likely not to exist. drupal_realpath should be acting on the path rather than the file so maybe use pathinfo to split the full path name into directory and file and only pass the directory through drupal_realpath?

Am I using this function correctly?

Comments

gdl’s picture

Hi!

As I understand it, there's a convention within Drupal that functions that begin with an underscore should be considered "private" (to crib an object-oriented programming term), and generally should not be called directly from outside the module that contains the function that starts with an underscore.

That said, I don't think that calling _imagemagick_convert() directly is the right way to do what you're describing. Instead, you might want to look at the most recent development version of ImageMagick, which incorporates some changes to allow format conversion. There's an implementation of an Image Style that does format conversion at #1235966: Implement image_imagemagick_convert_image that should be adaptable to a custom Image Style that does what you want.

Your question about whether drupal_realpath() should be called on the file or on the directory that will contain the destination file is a good one, though.

Cheers,
-G

dippers’s picture

@gdl: Thanks for the reply. I would be happy to use a public function if one existed. The imagecache_coloractions changes for imagemagick only work on jpg, gif or png files not pdfs. I cannot find any reference to format conversion in the latest dev.

Pdfs to jpgs used to be easy in D6 as you could upload a pdf file to an image file field but the stricter tests on D7 core image means this is no longer possible. You now have to upload the pdf as a file and implement a custom field formatter that calls the image style.

For now I will use a patched version of _imagemagick_convert that works perfectly.

sun’s picture

Status: Active » Postponed (maintainer needs more info)

The actual problem of this issue isn't clear to me.

Submitting your changes to _imagemagick_convert() as a patch might help to clarify this issue.

mondrake’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (outdated)

Drupal 7 is EOL