I'm using image_field cropping widget in a node. In that node I would like the cropped image to link to the un-cropped image. In the display fields page for that content type, it allows you to "link to original file", but it's actually linking to cropped version of the original file. I know that the original uncropped version still exists as I see it on the server, and when I go back to the cropping widget, the original still shows up (snapshot attached). I would just love to be able to link to it. I don't know if it makes any difference, but Im using colorbox plugin to display the enlarged image.

If you could help with a patch that would solve this, I would be happy to make a $150 donation.
Thanks much,
Dan

Comments

dandolino’s picture

Issue summary: View changes

changed $50 donation to to $100 donation

dandolino’s picture

Status: Active » Closed (won't fix)

Never Mind,
I'm not going to use the Image Field Crop. Been in queue too long. Just will use scale and crop image styles.
Cheers
Dan

dandolino’s picture

Issue summary: View changes

revised explanation

Brolag’s picture

I had the same issue. It looks like the Image crop module saves a backup of the original image and creates another one (the cropped one) with the name of the original. So if I have for example "drupal.jpg" it will rename it as "drupal_0.jpg" where "drupal_0.jpg" is the original one.

In the other hand, I'm using Colorbox module and it uses the original url for the image which is changed in this case by the cropped one.

I'm using Image Crop 7.x-1.1 and Colorbox 7.x-2.4.

As a temporal solution I created a custom theme function in order to validate wich url should the colorbox use.

/**
* Implementation of hook_theme_registry_alter()
*/
function colorboxcustom_theme_registry_alter(&$theme_registry){
   $theme_registry['colorbox_imagefield']['function'] = 'colorboxcustom_colorbox_imagefield';
}


/**
 * Replaces the current image path for the original image path.
 *
 * @param string $image_path
 *  A string with the current image path
 *
 * @return
 *  A string with the path of the original image
 */
function colorboxcustom_replace_image_path($image_path) {
      // Separates the file name from the extention of the file
      $url_aux = explode('.', $image_path);
      // Put the extention of the file in the begining of the array
      $url_reversed = array_reverse($url_aux);
      $url_text = '';
      // Creates the file path of the original image
      foreach ($url_reversed as $key => $value) {
          $url_text = '.' . $value . $url_text;
          if($key == 0){
              $url_text  = '_0' . $url_text;
          }
      }
      // Removes the extra dot in the begining of the string
      $url_text = substr($url_text, 1);

      return $url_text;
}

/**
 * Overrides the default colorbox_imafield theme
 *
 * @param array $variables
 *  Array with the theme variables.
 *
 * @return
 *  A string with the image link
 */
function colorboxcustom_colorbox_imagefield($variables) {

  if(isset($variables['image']['path'])){
      $url_text = colorboxcustom_replace_image_path($variables['image']['path']);
      // Validates if the file exists
      if (file_exists($url_text)) {
        // Replaces the file path for the original image path
        $variables['path'] =  file_create_url($url_text);
      }
  }
  
  $class = array('colorbox');
  if ($variables['image']['style_name'] == 'hide') {
    $image = '';
    $class[] = 'js-hide';
  }
  elseif (!empty($variables['image']['style_name'])) {
    $image = theme('image_style', $variables['image']);
  }
  else {
    $image = theme('image', $variables['image']);
  }
  $options = drupal_parse_url($variables['path']);
  $options += array(
    'html' => TRUE,
    'attributes' => array(
      'title' => $variables['title'],
      'class' => $class,
      'rel' => $variables['gid'],
    ),
    'language' => array('language' => NULL),
  );

  return l($image, $options['path'], $options);
}

amir simantov’s picture

Category: Support request » Bug report
Priority: Critical » Major
Issue summary: View changes
Status: Closed (won't fix) » Active

I am re-opening this issue and changing some of its attributes and would like to elaborate on it.

First, this module is a must in most of my projects, so thanks @yhager (module coder and maintainer). Second, I use the colorbox module quite a lot... So, I am tending to think that this might happen again in the future. Third, as the colorbox module is used many times to show big images in drupal projects, it may be of an interest of others to have this issue attended.

Now, it might be tempting the think that the problem is with colorbox, but I do not think so. Although the given hooking which supplied in the comment above is to tweak the display of colorbox, the problem lies in cropping module. The reason is because naturally any image-related module looks for the original name of the file; hence, the problem might occur in such other modules when used together with image crop module (this module). In my opinion, the original file - that is wisely saved and not thrown away after saving a cropped image - should be left with its original name, while the *cropped* version file will get whatever suffix needed for the colorbox module to function.

I am changing the category of the issue to 'Bug report' instead of 'Support request', as I think that it is, indeed, a bug of this module. However, if the code or logic of the module are highly relay on the underscore-zero pattern of the suffix, at may be wiser to change the category to 'Feature request', as the problematic behavior might be changed in future major versions only.

Also changed the priority from Critical to just Major; no one actually died resulting this bug :)

Thanks,
Amir

amir simantov’s picture

StatusFileSize
new2.32 KB

Uploaded the module which fixes the problem.

RumpledElf’s picture

Your help function in the attached zip file calls filter_filter but if you just take that out the module works great. I needed the same functionality and that was a great fast fix for it - thanks! :)

RumpledElf’s picture

Have run into the same issue again on a different site. Very similar patch to yours, this time to print out a field in a view that is using a different image style, rather than just getting the original. The required image style is considerably larger than the cropped image and we had complaints about the quality - it was resizing upwards!

This snippet gets around the issue that subsequent image styles are applied to the cropped version of the image, not the original.

It is in a views field tpl, and also links to the node containing the image.

<?php $uri = $row->field_field_image[0]['rendered']['#item']['uri']; ?>
<?php $uri = preg_replace('/.jpg/','_0.jpg',$uri); ?>
<?php $uri = preg_replace('/.jpeg/','_0.jpeg',$uri); ?>
<?php $uri = preg_replace('/.png/','_0.png',$uri); ?>
<?php $image_url =  image_style_url('news_featured',$uri); ?>
<a href="<?php print url('node/'.$row->nid); ?>" alt="<?php print $row->node_title; ?>"><img src="<?php print $image_url; ?>"></a>