Need help with imagefield_crop 6.x implementation
| Project: | ImageField |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Hi,
I am working on the 6.x version of imagefield_crop.module. I have got most of the things working (Thanks a million for the improved filefield+imagefield code!), but I need some assistance in one thing.
When the user crops the image, I copy the cropped image to the same file name. The problem is that the browser does not refresh the image after it is being changed. I am not sure what is the best approach to force a browser refresh. imagefield_crop provides only a widget, so I thought it should not mess around with filenames.
My best bet at the moment is to implement a formatter that will work like theme_imagefield_image(), but will add a '?' query string (like drupal_get_css() does). The problem with this is that the user will need to change the formatter manually, which seems like a hassle.
Do you have any suggestion on how to implement this? Maybe you are willing to consider a modification to imagefield code (some kind of notification that the image has changed)?
I believe the same problem will happen with imagefield itself if I upload a different image with the same filename.
Thanks again for a great module and beautiful code!

#1
this is actually a problem that affects core as well. the user's image gets written back to the same name and the visitor is forced to do a full refresh to get the newer image. if you wanted to roll a patch for this i'd consider it but there's not an elegant solution that immediately springs to my mind.
#2
Thanks for the quick reply.
How about this patch? I just hacked it at the moment, and it seems to work for me. Does it have any side effects I fail to see?
#3
that's actually a pretty good solution, the only downside is that you end up with an extra stat call which can be kind of expensive if you've got a bunch of files. we should have a timestamp in the $file object, it'd make sense to use that instead if it gets updated when the file is replaced.
#4
I'm afraid it doesn't.
The schema says:
'timestamp' => array('description' => t('UNIX timestamp for when the file was added.'),
and indeed the code sets the timestamp once, on
file_save_upload()(andfield_file_save_file()does the same).#5
field_file_save_file() should be updating the timestamp when the file is changed.
#6
Ok, I've rerolled the patch. If you can commit it soon to imagefield, it would be a great usability enhancement to imagefield_crop.
As a note, I am not using
field_file_save_file()functionality, since this is not a new file, merely a crop of an existing file. Therefore, I implemented the following inhook_file_update():<?phpfunction imagefield_crop_file_update($file) {
$file->timestamp = time();
drupal_write_record('files', $file, 'fid');
}
?>
I hope it's a fair use of this hook - let me know if there is a more appropriate way for this.
Thanks!
PS - sorry for the long delay.
#7
#8
committed to head. should look at also doing this in other places.... need better centralized file url generation.
#9
Thanks!
#10
Automatically closed -- issue fixed for 2 weeks with no activity.
#11
Is this patch still needed? I read it in the README.txt of ImageCache_Crop that I needed it. I just tried to patch imagefield.module and it failed. Then I tried to do it manually but the line in the patch to be removed has changed a bit.
Edit - Disregard, at first it wasn't working until I hit save and then edit but after my patch attempt I went back and created a new node again and it worked right off the bat! This ImageField Crop module is amazing!
#12
@ElijahLynn the patch was committed to imagefield long ago and it is no longer needed. Everything should work out of the box.
#13
Hello yhager,
The docu says that the patch is still needed
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/imagefield_...
=> link is on the projects homepage
It would be could to remove it to avoid confusion as it is no longer necessary
Regards, Tom
PS this module is a beauty
#14
@buckley: thanks, fixed.
#15
Still experiencing the same problem as stated in original issue.
Tested in Firefox, IE, and Safari with newest version of modules.
Is there a new patch or are others experiencing this as well?
#16
@trupal218: no, I do not experience this issue using the latest versions from all modules. please give more details - also check the URL of the image after cropping, it should contain a timestamp at the end, which is used to prevent caching by the browser.
#17
I've tested on a fresh drupal install and still encountering the same issue. I will do my best to explain:
ImageField 6.x-3.2 2009-Oct-20
Imagefield Crop 6.x-1.x-dev 2009-Nov-05
Imagecache 6.x-2.x-dev 2009-Oct-09
Content Profile 6.x-1.x-dev 2009-Nov-04
I have cleared cache / ran cron / ran update.php
-I created a imagecache preset called 'profile' 230x230 pixels.
-In profile edit page I upload an image and select the area to crop and then press Save, which takes me to the profile view page.
No problem at this point.
-I go back to profile edit page and select a different area to crop and then press Save, which takes me back to the profile view page.
Issue is here: The profile image does not show the newly cropped area UNLESS the browser is refreshed (shows the old cropped image).
Can anyone please give me pointers in what may be causing this?
#18
Hello yhager,
I am still seeing the issue. I realized it is not with the url of the image, but the issue is that the newly re-cropped image shown on Views or on User Profile page. I am having to force refresh the view or the user profile page in order for the newly cropped picture to show.
Is this by design?
Or should re-cropped update the picture on these other pages?
Thanks in advance!
#19
@trupal218: the problem you are seeing stems from the fact that browsers assume image URLs never change, which is not the case for image cropping module. The original issue was solved by adding "intelligence" to imagefield module so that it will force the browser to refresh when an image was updated. Other modules, like content profile, are not aware of this fact, and demand a manual browser refresh.
There are two ways to solve this:
1) If you are a coder, you can prepare a patch to content profile in the spirit of the patch in comment #6, and hope it will be accepted upstream;
2) You can also solve this at the theme layer, modifying the image url to include the timestamp;
Closing this one.