Is there a nice way, that i don't have my Original Pics on my HomePage ( they take a lot of Storage..... ???
Ideas i have would be to keep the Originals at Home using DSL & DynDNS
or to have the Original replaced by the resized... but then i would loose the EXIF Informations...
Any Hack around for this :roll:
Regards
Simon
Posts: 3
I would like to do the same thing... I take high quality pictures, and typically use another image resizing program before I upload them, but for other users that are uploading pictures, is there are way to NOT keep the original image (sometimes well over 2 megs each) and have a sort of hard limit of 640pixels?
-gvb
Posts: 314
There's no hack for this, gallery 1.x was designed with a small number of people that upload photos in mind. It was assumed that those people know what they're doing. Therefore all image operations are based on the original image and deleting them will screw up your gallery.
To OP: can't you use a program that resizes photos and keeps the exif data?
Posts: 5
Hi!
Yaeh this Feature would be great!! I also would like to have the Original replaced by the resized.
brick_top aka pEtEr
Posts: 18
jhead (http://www.sentex.net/~mwandel/jhead/) will copy the EXIF information from one jpeg to another; it will even work on a directory full.
I use the excellent 500kb EXIF Viewer program (http://home.pacbell.net/michal_k/exif_v.html) to view the images off the camera,aa create reduced sized pictures and then jhead to reinstate the EXIF information.
I upload the reduced sized ones to my gallery.
However, that said, I am thinking about using mogrify on the server to reduce again any pictures that are less popular (with jhead again to reinstate the data).
Perhaps gallery can be altered to depend on jhead thus providing the facility to ditch the original?
M.
Posts: 3
Sounds like an idea :smile:
Basically, the ability to setup a gallery for not so computer savy users. They could theoretically, just take their full quality images and upload them not having to do any resizing, etc... and the server would reduce the image size and quality without wasting tons of space saving the original image.
-gvb
Posts: 314
This should actually be not that hard to accomplish. It would involve editing the save_photos.php around line 313. Photos get inserted in the temp dir, before they're moved to the album location, when you would resize them before adding them to the album location, this would do the trick.
Note1: I don't know what will happen to EXIF data
Note2: This should be done in the gallery_remote.php file as well.
Unfortunately I know just enough PHP to make my layout modifications, this won't be achievable by me. But it'll be a nice function for sure.
Posts: 89
Could someone with more programming knowledge please look into this feature. I know a lot of people are using Gallery as a global photo management system for a site of users, and this mod would really help a lot of us out with both storage and bandwidth issues.
If this can't be done easily, how hard would it be to reject any images that are over, say 640x480 in dimmension?
Thanks,
Jason
Posts: 6
hi folks
i also have that storage problem (uploading 1600x1200 pic ~ 400k per pic is much)
well i tried to understand the code and tried to program that the original pic will be deleted after resizing, but it didnt work.
now i will try to programm it with the idea posted 2 posts ago (resizing the original).
ill answer here if i got a solution
cya
kb
Posts: 6
hi folks!
after hrs of researching the code i DID it!!
u have to add the following code after line #329 (before the line: $err = $gallery->album->addPhoto($file, $tag, $mangledFilename, $caption);) :
$dir = $gallery->app->tmpDir;
fs_copy($file, "$dir/$mangledFilename.$tag");
$file = "$dir/$mangledFilename.$tag";
$temp_files[$file]++;
resize_image("$file", "$dir/$mangledFilename.temp.$tag", "640");
$file = "$dir/$mangledFilename.temp.$tag";
$temp_files[$file]++;
this will copy the original file to the temp dir specified in the config.php file, resize the image to 640x480 and set this file as original to the following instruction (copying to the album folder etc);
i tried it with a few pics and it works. BUT you have to switch the resize_size to off
if u dont do that, you will get a 2. resized pic aswell as the "original" (resized one).
hope it will work on your system (i didnt change the gallery_remote.php cuz i dont need it *g*)
cya
kb
Posts: 89
Nice work Killerblade! This will be such a resource, and time saver for me! Now if I can just figure out how to sort albums by last update, I'll be done modding Gallery.
Posts: 3474
Hi folks. Not sure if this will help...
I churned out a bit of code which will resize the original photos in all the albums (or just the ones you select). It evolved out of a need for me to resize all the photos in my album because I was running out of hard drive space. Anyhow, it will resize your images, preserves EXIF data on jpegs, allows resizing of the ".sized" images, and can rebuild the thumbnails while you're at it.
So while this won't resize when someone uploads, it'll at least do it retroactively when you run the code.
I recently went in and tried to make the code "foolproof", so I've decided to share it here. For more, visit http://www.beckettmw.com/testgallery . I've set the page up so you can actually play with the feature on my test site to see how it works before you try it out yourself.
If you do try it out yourself, please let me know how it goes, so I can change things if necessary.
Regards,
-Beckett (beck@beckettmw.com)
Posts: 18
Hi Beckett,
Thanks for this contribution. I, for one, appreciate it!
The only important modification I can see that I need is to show a nested list of album names on the left hand side. This is important for me because I want to resize a deeply nested album without affecting the ones above it. For your test album, this is to resize album testnest without resizing album testalbum.
Perhaps this is what you meant by: Coming soon to this location: changing album properties for every album you select in the list to the left all at once. Visit beckettmw.com/testgallery to check for updates. ?
Other issues:
The second thing is I find the .sized option confusing. I'd probably remove it but I would be interested to here whether other users think the same.
In the long term it would be best for gallery to have a generic mechanism for selecting albums/pictures. This is so that the selection mechanism can be integrated with other functions. For example, I want to make smallest those pictures that are least popular and popularity of a picture depends on people voting for that picture!
Something needs to be done about the naming of the term 'resize' as gallery already uses that word to mean something else.
Keep up the good work, I'm dying for space on my server!
Thanks,
Martin. :grin:
Posts: 18
If you install gallery under postnuke, you'll find that myresize does not invoke postnuke's login sequence like it should. Instead it (looks like it) invokes gallery's built in routine.
Regards, M.
Posts: 18
In fact, I don't think it works at all properly under postnuke, the main page loads but when attempting to resize I get:
Sorry, you can't access this file directly...
Regards,
M.
Posts: 314
Beckett, thanx a lot, it looks like a really great tool, and I'm going to try it for sure.
As for the previous poster, for me it made complete sense, the .sized option should definitely be there, although I'm not sure of the necessity, since Gallery can already do this, and the quality would be better when higher resolution images are used to make the resize from.
Posts: 3
So this feature will be part of G2 :wink:
-gvb
Posts: 8
Killerblade,
I have been looking for something that would do this for over a year, thanks for the code :grin:
One dumb question about your instructions above:
Where (what file(s) do I modify) to switch the resize_size to off???
Thank you again,
Teletubby
Posts: 1
TT: He meant in the initial configuration script, the auto-resize feature.
I've taken a crack at this today, and think I have an interim solution. (warning though, I do not write in PHP, so it is all pure hacking. )
I took Killerblade's code and added flags to the base settings for Gallery, so that you can set/clear/change the default and each albums resize-to value. You One minor/major flaw is that I cannot tell if a file _needs_ to be resized (eg is smaller), it just resizes them all. Exif isn't cooperating so it needs an alternate method.
Example album: <!-- BBCode Start --><A HREF="http://www.vestus.com/scripts/gallery/test/" TARGET="_blank">Test gallery</A><!-- BBCode End -->
(Album will be removed after 12/1/02 (or sooner if abused.)) user: test pass: test
Archive file:
<!-- BBCode Start --><A HREF="http://www.vestus.com/pub/Gallery131-resize0.3.tar.gz" TARGET="_blank">Gallery131-resize0.3.tar.gz</A><!-- BBCode End --> has all the files I changed, 1.3.1 backups and a small readme. Simply extract over your base /gallery directory. You will/may have to change permissions on /gallery/setup.
(If you want to look at the code changes, base_size is the flag I added. )
Kudos to KB for the resizing bit.
Good Luck
Vestus (spam@vestus.com)
Posts: 2
Great idea! I have a question though. I have numerous albums that I've created in the past with resize_size set to 600. Now I want to get rid of the "sized" images and just keep the thumbnail and the original.
Any idea how to change the value of resize_size retroactively?
Thanks,
Torrey
Posts: 65
My suggestion is completely outside of Gallery and PHP etc. If you are running wondows, search for all files with the wildcard *.sized.* and then simply delete them!
Just my ¢2 worth!
Ajoy
Posts: 3474
I wouldn't recommend that... it will hose your database and break Gallery.
However, if you download my myresize code (mentioned above), then enter an absurdly large number into the max. size box (say, 20000 pixels), and put the same number (or higher) into the ".sized" size box, then it will go through and remove all of the .sized images without touching your originals.
(It will then update the resize size to this value so that your future uploads will not generate the .sized images...).
Hope that helps,
-Beckett (beck@beckettmw.com)
Posts: 2
:grin: The myresize.php is very cool! Worked no problem.
Thanks,
Torrey
Posts: 4
For those of us who are completely ignorant, can you please post which file this code is supposed to go in? if anybody knows, please help. I don't have enough space on my server for two versions of the same picture.
Posts: 3474
killerblade was referring to save_photos.php.
-Beckett (
)
Posts: 185
Thanks for both hacks: the one for future photos saved (killerblade) and the one for past ones (beckett). They worked fine, until at one point it froze (not sure if my laptop lost connection or something), then it ended up freezing our server, and needed a restart. Now I have photos with broken thumbs and recreating thumbs doesn't work, even though when you click them, you get the resized photos. At the moment, I'm going to look up a 'replace photo" in the forums, b/c i was sure I saw a hack for that...
actually i'm gonna try to edit the thumb now to see if that works...
After the restart, I've been using it without problems for my other galleries..
Posts: 185
Editing the thumb works, as long as I double click to reset its position. The rectangle starts off the image at first.
The script will freeze after a while but at least this time it didn't freeze the server, I just restart the script and it quickly goes through folders it's already done and goes to where it left off eventually..
the next time it freezes, I'll check the error log to see what it says and post it here.
Posts: 185
Looks like it just timed out or something, in regards to the 30 secs I allowed so I'm moving it up to 90.
again, it does work, so thanks!
Posts: 3474
Yeah. NetPBM and Jhead operations take forever. So the script is about as fast as it can be. If you use ImageMagick, it'll probably be a little faster.
I really should put something in the readme about doing resizes in smaller batches to avoid the timeouts (which are safe, but just a hassle because you have to restart again).
Hmm... the freezing sounds bizarre. If you have an older version of PHP it could be running into memory problems ??
Posts: 185
it's 4.23 we run our own server so we update it (not sure if we're doing 4.3.0 yet) but i think the page was timing out and then i also lost my connection on my laptop (damn wireless noise).
either way, it occassionally stops mid process for resizing or redoing the thumbs, but i just restart and it gets through it and finishes it. strange, but it's not a problem really, just takes a little more time.
i'm using it on my 2nd gallery right now and it's fine so far. either way, it saves me a lot of time.
I do notice that the messed up thumbs (mostly the highlight photo ones) where i selected a smaller part of the thumb in edit thumbnail, then when it gets resized, that box I made is off the picture, causing it to be blank until i reedit the thumb. This was in the first gallery i was working on. my 2nd gallery hasn't had a problem. maybe it was just a freak thing. I'll let you know as I update my other gallery ... in small batches!
Again, thanks a lot for the code
Posts: 3
killerblade's chunk of code looks like what I need, but before I implement it, a couple questions...
Will this downsample images with high dpi resolutions to 72 dpi? Will aspect ratios be preserved? And will the client be notified that their image was too big and has been resized?
Posts: 3474
Will this downsample images with high dpi resolutions to 72 dpi?
Okay. This requires explanation. DPIs above 72 are really a printer-only phenomenon, and not really part of a JPEG's spec. Browsers display JPEGs at 72 DPI regardless of what their target DPI is set to, so DPI is irrelevant in this case. But at least for NetPBM, the DPI setting will be lost on resize. I'm not sure about ImageMagick. Again, this shouldn't matter, since the images are being displayed in the browser anyhow. I once spent 20 minutes trying to find out how to force a DPI setting in NetPBM but I didn't find a way.
Will aspect ratios be preserved?
Yes.
And will the client be notified that their image was too big and has been resized?
No. You can add some code pretty easily to print out a message though. Let me know if you need help wiith that.
Also, EXIF data in jpegs will *not* be preserved with killerblade's original code. If this is important, add the bit of code I posted in <!-- BBCode Start --><A HREF="http://gallery.menalto.com/modules.php?op=modload&name=phpBB_14&file=index&action=viewtopic&topic=1424&5465" TARGET="_blank">this thread</A><!-- BBCode End -->.
-Beckett (
)
Posts: 3
I don't care so much about EXIF stuff, 'cuz my gallery will mostly consist of hand-drawn art that has been scanned instead of true digital photos.
As for the DPI stuff, I know browsers will always display at 72 dpi, but sometimes, back when I was running a gallery like what this script does, but by hand ( :sad: ) I've had people try to send me images that "look" small to their eyes, but are 300 dpi and therefore have an unwieldy filesize. I'll be using ImageMagick, so I guess I'll just experiment and see what it does.
As for implementing an error message... yeah, I might need a little help with that. :smile: I pretty much know only enough PHP to butcher, not truly "hack..." I'll give it a try, though.
Posts: 3474
Just add something like this to the code (make sure it's inside the if() statement).
print "Image too large. Shrinking it for you...<br />n";
You could print out the resized size, but you'll have to do a couple lines of math, and I'll let you figure that out for yourself. :wink:
-Beckett (
)
Posts: 7
Killerblade's code seems to be exactly what I am looking for. But wouldn't it have been easier to simply use the resize feature built in (imagename.sized.jpg) and just code the ability to delete the original and remove the view full image option?
I am just throwing this out to see what the experts think, not saying there is anything wrong with killerblade's code hack :smile:
Posts: 314
Actually, this is how this entire discussion started, way back in 2002 :wink:
No, it's not possible to delete the original image, Gallery depends on it for most image operations (move, resize etc.). Deleting the original image will simply screw up your Gallery, so it's like the last resort option. Killerblade's code is the first resort :smile:
Posts: 8
thx killerblade GREAT job!
i did a little fine tuning, which allows to:
selcect the "Auto-Resize"-values in "properties" for each album
use "off" in "Auto-Resize" which will then display pics in original size
original killerblade hack for save_photos.php:
fine tuned:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
// RESIZE HACK by killerblade tuned by shine_162
if ($gallery->album->fields["resize_size"]!="off"){
$dir = $gallery->app->tmpDir;
fs_copy($file, "$dir/$mangledFilename.$tag");
$file = "$dir/$mangledFilename.$tag";
$temp_files[$file]++;
resize_image("$file", "$dir/$mangledFilename.temp.$tag", $gallery->album->fields["resize_size"]);
$file = "$dir/$mangledFilename.temp.$tag";
$temp_files[$file]++;
// you may delete the following line if you don't want to see max-size information
echo '.. pics will be resized to <b>'.$gallery->album->fields["resize_size"]. '</b> max. lenght/high if larger';
}
// end resize hack
</TD></TR></TABLE><!-- BBCode End -->
Posts: 3
Hello everybody, this patch is great. I just want to ask something else, I don't know if I miss something in the thread and I don't see this discussion, but I will like to know if is possible in someway to keep the date of creation of the original pictures. Because as you have notice the date is modified I will like to preserve that.
Regards, Max.
Posts: 185
Like Picture Taken Date, camera used, etc..? I think that's the EXIF data. Killerblade's code alters the pic and doesn't preserve that data, however, beckett posted a link to a thread above which has the code you plug in to preserve that data... just scroll up a little. Hope that helps.
Posts: 3
Exactly that was it, thank you dtdgoomba.
Cheers.
Posts: 6
Where does this go in Gallery 1.3.4? Line 329 looks nothing like the reference point mentioned by killerblade. Thanks!
Posts: 3474
ronpoz, in v.1.3.4, this code got moved to the processNewImage() function in util.php. It's no longer in save_photos.php.
-Beckett (
)
Posts: 6
in gallery 1.3.4 the line:
>$err = $gallery->album->addPhoto($file, $tag, $mangledFilename, $caption)
has moved to
util.php
#1482
thank you all for your replies
it was a honor to create such a hack ;)
mfg
killerblade
Posts: 110
I have combined the code of killerblade and of beckett for the EXIF data and inserted the code at line1482 of util.php, but am getting errors when I upload a zip file. Can anybody verify that the following code is correct:
$dimensions = getimagesize($file);
if($dimensions[0] > "640" || $dimensions[1] > "640") {
$dir = $gallery->app->tmpDir;
fs_copy($file, "$dir/$mangledFilename.$tag");
$file = "$dir/$mangledFilename.$tag";
$temp_files[$file]++;
resize_image("$file", "$dir/$mangledFilename.temp.$tag", "640");
//copy over EXIF data if a jpeg
if (!strcmp($tag, "jpg")) {
$jhead = $gallery->app->use_exif;
exec_wrapper(fs_import_filename($jhead, 1) . " -te "
. fs_import_filename("$dir/$mangledFilename.$tag", 1) . " "
. fs_import_filename("$dir/$mangledFilename.temp.$tag", 1));
}
$file = "$dir/$mangledFilename.temp.$tag";
$temp_files[$file]++;
}
Posts: 110
killerblade, becket....?
Posts: 3474
Well at first glance the code *looks* okay. Please either post your additions in context of util.php or email me your file. Also, please tell us the *exact* error you're receiving.
-Beckett (
)
Posts: 81
Beckett,
Does your resize script compatible with the last release of gallery -> 1.4-RC1 ?
Thanks for this great script!
TOM
Posts: 3474
I have no idea. Wanna be my guinea pig and test it out??
I don't have time right now to check it out.
It was certainly working with the CVS version a couple weeks ago when I added some new photos to my own website.
Once 1.4 final is released, I'll have time to look into it if the code needs to be updated.
-Beckett (
)
Posts: 135
I use your resize script with the latest version and it works perfect. I have 2 albums running on one site with over 4,000 pictures and I have them all reduced. It works perfect.
Thanks again for it...
Posts: 3474
Great news! Thanks.
Posts: 114
Guys this has no effect for me, hows it supposed to work? How do I initiate it, when adding pics?
This is the code I have insterted into util.php