If the user uploads an image in the imagefield directly then the uploaded image should take precedent and there shouldn't be a PDF-based image generated at all.

Inserting these lines inside the pdf_to_image_generate_process function around line 370 (right after the comment that says "// Should I check if the target field is already populated and stop then?" in pdf_to_image.module

 // Don't generate a new image if the PDF file didn't change.
  if ($entity->{$field_id}['und'][0]['fid'] == $entity->original->{$field_id}['und'][0]['fid'] ) {
    return;
  }
  // Don't generate an image if new node and the imagefield has image uploaded in it.
  if ((!$entity->original) && ($entity->{$target_field}['und'][0]['fid'])) {
    return;
  }

I'll roll this as a patch and attach to a followup comment.

Comments

artis’s picture

Title: Generated Image always supperseeds any image uploaded directly into the image field. » Allow image uploaded directly into the image field to supersede the generated image.
Status: Active » Needs review
StatusFileSize
new1.09 KB
dman’s picture

Yes, that was the intended behavior from the start. I thought it used to do that.
If that logic has been lost during some of the logical refactoring over time, it's good to get it back again!!!

dman’s picture

I tested it by uploading a manual image over an existing doc page, and also from new.
Seems to do what it says BUT I'm getting

Notice: Undefined property: stdClass::$original in pdf_to_image_generate_process() (line 370 of /private/var/www/drupal7/sites/all/modules/patched/pdf_to_imagefield/pdf_to_image.module).
Notice: Trying to get property of non-object in pdf_to_image_generate_process() (line 370 of /private/var/www/drupal7/sites/all/modules/patched/pdf_to_imagefield/pdf_to_image.module).
Notice: Undefined property: stdClass::$original in pdf_to_image_generate_process() (line 374 of /private/var/www/drupal7/sites/all/modules/patched/pdf_to_imagefield/pdf_to_image.module).

Code that uses [und] etc is always at risk of introducing problems like this. (Not because of [und], but it's a sign we are not using the full API correctly)
See http://www.davereid.net/content/hlkd7fotw-field-get-items about how to use field_get_items()
.. I'll sort that out..

dman’s picture

Here is a remake of that logic.

Note, it's significantly different. Uses the API to file the existing fids, and treats the 'new' node and the 'updated' node as exclusive possibilities.
Basically a full rewrite.

  • dman committed 47f79e5 on 7.x-3.x
    Issue #2049725 by dman, artis: Allow image uploaded directly into the...
hitchshock’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

We stopped supporting the D7 version, so the ticket will be closed, but thanks to everyone who was working on the ticket!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.