How do I add large sized versions of existing photos?
|
samuurai
Joined: 2006-01-03
Posts: 15 |
Posted: Tue, 2006-01-03 17:12
|
|
I'm running Gallery2 and i've uploaded about 1000 photos and added captions to nearly all of them. I used the Windows XP upload feature because it's so damn easy, but I made it resize all of my photos before uploading. I'm now wondering how I can add my the original quality photos to the gallery so they can be displayed if the person viewing the gallery wishes. Please don't tell me I have to re-add everything and re-type all of my captions... !! |
|
| Login or register to post comments |

Posts: 32168
actually you have to.
an alternative is to replace all files in g2data/albums/ and then using a script of your own to "rescan" all images such that g2 has hte right meta data about them in the database.
and g2 will recreate resizes and thumbnails from the new high quality images.
@rescan script:
something like
require_once(dirname(__FILE__) . '/embed.php'); $ret = GalleryEmbed::init(array('fullInit' => true)); if ($ret->isError()) { print $ret->getAsHtml(); exit; } global $gallery; $gallery->guaranteeTimeLimit(120); list ($ret, $ids) = GalleryCoreApi::fetchAllItemIds('GalleryPhotoItem'); if ($ret->isError()) { print $ret->getAsHtml(); exit; } print "Rescanning " . count($ids) . " images\n<br>"; foreach ($ids as $id) { $gallery->guaranteeTimeLimit(60); list ($ret, $photo) = GalleryCoreApi::loadEntitiesById($id); if ($ret->isError()) { print $ret->getAsHtml(); exit; } list ($ret, $path) = $photo->fetchPath(); if ($ret->isError()) { print $ret->getAsHtml(); exit; } print "Processing '$path'\n<br>"; list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($id); if ($ret->isError()) { print $ret->getAsHtml(); exit; } $ret = $photo->rescan(); if ($ret->isError()) { print $ret->getAsHtml(); exit; } $ret = $photo->save(); if ($ret->isError()) { print $ret->getAsHtml(); exit; } $ret = GalleryCoreApi::releaseLocks($lockId); if ($ret->isError()) { print $ret->getAsHtml(); exit; } $ret = GalleryCoreApi::invalidateDerivativeDimensionsBySourceIds(array($id)); if ($ret->isError()) { print $ret->getAsHtml(); exit; } } $ret = GalleryEmbed::done(); if ($ret->isError()) { print $ret->getAsHtml(); exit; }alternatively, there's also a "reupload module" on codex.gallery2.org -> user contributions, haven't tried it though.
Posts: 15
Hi Valiant...
I've had a look at the reupload module, i've installed it, activated it, but can't figure it out.
How do I go about running that script? Do I paste it into a file, then access it in a web browser? I've never done any PHP before.
Thanks mate!
B
Posts: 15
Oh, I found where the reupload module is... it's in "Edit Photo"...
I'd prefer to do it scripted though, as it'll be less manual.
Posts: 32168
ok, i've added some measures to prevent timeouts during the execution.
1. backup your gallery (database and g2data folder)
2. replace the files in your g2data/albums/ folder. do not remove any files, do not move any files, just replace the files with a new version. nothing else is permitted.
3. put the above code into a file rescan.php and put the file into your gallery2 folder
4. browse with your preferred webbrowser to http://www.yourwebsite.com/gallery2/rescan.php
5. remove rescan.php from your gallery2 folder
Posts: 15
Hi Again valiant..
ok, after a couple of hours messing around with macros in word i've moved my 1000+ high quality photos in to their corresponding dirs.
I pasted the script above into a file and tried to run it, but came up with errors. You can see it at http://87.74.42.101/gallery/rescan.php
I tried changing its ownership to root and apache. Although most of gallery's .php files are owned by "1000".
Thanks for your help on this. Very much appreciated.
Beren
Posts: 32168
heh, you need to add
<?php
at the top and
?>
at the end. else it's not recognized as php code.
Posts: 15
Ahh
Like I said, i've never done and PHP before 
It does something now, but it has a bunch of errors. You can see yourself from the link above....
Thanks,
B
Posts: 15
Wait a minute... It's done it! Well, I checked 5 photos and they're now the high quality photos!!!
This is awesome!!!
Was that error anything I need to worry about? If not, mission accomplished!!!!
You rock dude.. thanks a million
Beren
Posts: 32168
it's done it, but not for all items!
i've changed the above script to print out the item that is being processed.
so you know which file is the problem when you get an error.
Posts: 15
Ok, that has done it, my friend..... you rock! One of my files didn't copy before, thats why it didn't work...
Thanks for taking the time to help me. I really appreciate it. You saved me hours and hours or work!
Take care,
B.
Posts: 5
I switched one directory with my new files (which are all smaller). I ran rescan.php and it worked fine. I looked at my gallery, and that one album showed that each image was "UPDATED". It also blew out my thumbnail settings, but that's not a big deal to fix, as I can do that all at once. All-in-all, I'm very happy with this work-around.
http://gallery.chromatest.net/v/Burn/BM2K5/01TheDriveUp-Sat/
I did get a bunch of errors at the end though:
Error (ERROR_OBSOLETE_DATA) : UPDATE g2_Entity SET g_modificationTimestamp=?,g_serialNumber=? WHERE g_id=? AND g_serialNumber=? (1137454394|3|1561|2)
* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 588 (gallerystatus::error)
* in modules/core/classes/GalleryStorage.class at line 142 (mysqldatabasestorage::saveentity)
* in modules/core/classes/GalleryEntity.class at line 294 (gallerystorage::saveentity)
* in modules/core/classes/GalleryDerivative.class at line 276 (gallerychildentity::save)
* in modules/core/classes/helpers/GalleryDerivativeHelper_advanced.class at line 625 (galleryderivativeimage::save)
* in modules/core/classes/helpers/GalleryDerivativeHelper_advanced.class at line 639 (galleryderivativehelper_advanced::invalidatederivativedimensionsbysourceids)
* in modules/core/classes/helpers/GalleryDerivativeHelper_advanced.class at line 639 (galleryderivativehelper_advanced::invalidatederivativedimensionsbysourceids)
* in modules/core/classes/GalleryCoreApi.class at line 868 (galleryderivativehelper_advanced::invalidatederivativedimensionsbysourceids)
* in rescan.php at line 25 (gallerycoreapi::invalidatederivativedimensionsbysourceids)
Posts: 32168
delete the db cache (site admin -> maintenance | or http://gallery.chromatest.net/lib/support/ -> cache)
Posts: 5
And for other people using the information in this thread, the rescan.php script breaks when it hits an invalid file (broken upload, etc). Reupload the invalid files and the script will work properly.
Posts: 55
Awesome script, thanks Valiant.
I used this line to resize (images that were just too big) in my gallery:
find . -iname '*.jpg' -exec convert -resize "1600x1600>" '{}' '{}' \;May come in handy for someone else.
Posts: 16
The rescan script appears not to work with v2.1
I have just upgraded, reuploaded high-res versions of existing photos and then tried to run rescan.php but am getting this error:
Fatal error: Call to a member function isError() on a non-object in /home/djones/public_html/gallery/rescan.php on line 4
Can anyone shed any light on this?
Thanks, David
Posts: 16
bump
Posts: 55
I've quickly updated the code for Gallery 2.1 and added excessive comments so others can follow the code
<?php header('Content-type: text/plain'); // Load the Gallery API require_once(dirname(__FILE__) . '/embed.php'); $ret = GalleryEmbed::init(array('fullInit' => true)); if ($ret) { echo $ret->getAsText(); exit; } // Grab all the photos $gallery->guaranteeTimeLimit(120); list ($ret, $ids) = GalleryCoreApi::fetchAllItemIds('GalleryPhotoItem'); if ($ret) { echo $ret->getAsText(); exit; } // Loop the photos echo "Rescanning " . count($ids) . " images\n"; foreach ($ids as $id) { // Load the photo object $gallery->guaranteeTimeLimit(60); list ($ret, $photo) = GalleryCoreApi::loadEntitiesById($id); if ($ret) { echo $ret->getAsText(); exit; } // Find the image, lock it, rescan and save list ($ret, $path) = $photo->fetchPath(); if ($ret) { echo $ret->getAsText(); exit; } echo "Processing '$path'\n"; list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($id); if ($ret) { echo $ret->getAsText(); exit; } $ret = $photo->rescan(); if ($ret) { echo $ret->getAsText(); exit; } $ret = $photo->save(); if ($ret) { echo $ret->getAsText(); exit; } // Free the image lock $ret = GalleryCoreApi::releaseLocks($lockId); if ($ret) { echo $ret->getAsText(); exit; } // Delete all the photo derivatives $ret = GalleryCoreApi::invalidateDerivativeDimensionsBySourceIds(array($id)); if ($ret) { echo $ret->getAsText(); exit; } } // Finish $ret = GalleryEmbed::done(); if ($ret) { echo $ret->getAsText(); exit; } ?>Posts: 16
That worked a treat! You're a star, thank you!
Posts: 47
I have uploaded the high res and run the rescan.php script, there is no error in the report. No problem with the newly generated thumbnails and resized images.
However, when trying to see the full size image at photo page, only a small top portion of the image is shown.
Any help?
Gallery version = 2.1.1 core 1.1.0.1
PHP version = 5.1.1 apache2handler
Webserver = Apache/2.2.0 (Win32) DAV/2 mod_ssl/2.2.0 OpenSSL/0.9.8a mod_autoindex_color PHP/5.1.1
Database = mysql 5.0.18, lock.system=database
Toolkits = SquareThumb, Exif, ImageMagick, Ffmpeg, Thumbnail
Acceleration = none, none
Operating system = Windows NT THINKPADX31 5.1 build 2600
Default theme = matrix
Locale = en_GB
Browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; iebar; .NET CLR 1.1.4322)
Posts: 1
THANK you ever so much for the updated the code for Gallery 2.1
It worked Great and I had over 500 pictures in my gallery at lakenheathhs.com
ladykathleen
Posts: 8
Uh... hoping someone will read this post and point me in the right way here. :P
I'll give this script a rip and see if it works for what I'm trying to do.
), would this work for causing Gallery 2.1.2 to re-evaluate all photos in the Album folder (and subs, of course) and rebuild the web content as appropriate?
In the mean time (before I screw things up
What I'm trying to do is simply "sync" my full photo library (80K+ images) to the Album folder and have Gallery2 reflect that as simply (read "as little user interaction") as possible.
Is this the ticket? or better to use the "get from local server" import method?
or is there a better way to do this? that will accommodate changes in sub-folders? ideally only messing with changes?
Posts: 1
This is off-topic, but since a lot of people who are looking to scale down all their images due to low disk space problems get referred to this post, I am putting it here. I wrote a PHP script that shrinks all images above a certain threshold (eg 1280x1024) down to that size. This way, you won't need to download all the images and perform the batch resize manually. Note that this is independent of Gallery, and you will still need to apply the above PHP script to rescan all the images. You must scroll to the very bottom and customize the line that executes: resizeTree(1280, 1024, '/home/myAccountName/g2data/albums', true). Maybe somebody else can take the time to integrate valiant's script into this and make it more user friendly. Or maybe someday when I have time, I might even write a module to do it all for you!
---BEGIN COPY/PASTE---
Posts: 32168
there is already a module for that.
the sizelimit module shrinks images on upload.
but you can also apply it to the existing images in your albums.
Posts: 1
I just used the rescan code to reupload smaller jpegs to reclaim disk space on my web site. I had to add some logic to test for a null error retun code. After I added some if statements, the logic worked great. Here is the new code:
<?php
print "rescan started";
require_once(dirname(__FILE__) . '/embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true));
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
print "after if";
global $gallery;
$gallery->guaranteeTimeLimit(120);
print "after global and time limit";
list ($ret, $ids) = GalleryCoreApi::fetchAllItemIds('GalleryPhotoItem');
print "after list";
if ($ret == "") {print "ret = null";}
// if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
print "after if";
print "Rescanning " . count($ids) . " images\n<br>";
foreach ($ids as $id) {
$gallery->guaranteeTimeLimit(60);
list ($ret, $photo) = GalleryCoreApi::loadEntitiesById($id);
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
list ($ret, $path) = $photo->fetchPath();
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
print "Processing '$path'\n<br>";
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($id);
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
$ret = $photo->rescan();
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
$ret = $photo->save();
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
$ret = GalleryCoreApi::releaseLocks($lockId);
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
$ret = GalleryCoreApi::invalidateDerivativeDimensionsBySourceIds(array($id));
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
}
$ret = GalleryEmbed::done();
if (($ret!="")&&($ret->isError())) { print $ret->getAsHtml(); exit; }
print "rescan completed";
?>
Posts: 100
I'd like to run this "rescan" script on specific albums instead of on all albums. Valiant indicated this would be possible by changing the start of the script accordingly (see here: http://gallery.menalto.com/node/57170).
It seems this would be the relevant line of code to change:
list ($ret, $ids) = GalleryCoreApi::fetchAllItemIds('GalleryPhotoItem');My guess is that I need to replace 'fetchAllItemIds" by setting the specific ItemID/g_id here. However, I do not know the proper syntax. Can anyone help?
Posts: 32168
instead of GalleryCoreApi::fetchAllItemIds('GalleryPhotoItem'); you'll have to use
list ($ret, $ids) = GalleryCoreApi::fetchDescendentItemIds($album);
whereas $album is the album object that you must have loaded previously, e.g. with
list ($ret, $album) = GalleryCoreApi::loadEntitiesById(7);
whereas 7 is just an example. you need to find out the itemId of the album for which you'd like to do this.
and $ids isn't a list of all photos anymore. it includes movies and albums and other items as well. you'll have to filter it.
--------------
Doumentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 100
Thanks valiant. Is the "itemID" for an album the same as the "g_id" for that album in the MySQL database?
If so, and my existing album has g_id=147 (it has already been loaded), then I would change the line in your script as follows:
list ($ret, $ids) = GalleryCoreApi::fetchDescendentItemIds(147);Posts: 100
This unfortunately did not work for me. I replaced the aforementioned line in the script and put in the appropriate itemID (which I assumed is the same as the g_id from the database). After running rescan.php, I get the following:
Error (ERROR_BAD_PARAMETER)<b>in</b> modules/core/classes/helpers/GalleryChildEntityHelper_simple.class <b>at line</b> 301 (gallerycoreapi::error)
<b>in</b> modules/core/classes/helpers/GalleryChildEntityHelper_simple.class <b>at line</b> 379 (gallerychildentityhelper_simple::_fetchdescendentitemids)
<b>in</b> modules/core/classes/GalleryCoreApi.class <b>at line</b> 2319 (gallerychildentityhelper_simple::fetchdescendentitemids)
<b>in</b> rescan.php <b>at line</b> 11 (gallerycoreapi::fetchdescendentitemids)
I'm not sure what to make of this error. Could it be that the script doesn't work with Gallery 2.2?
---------------------------------
Gallery version = 2.2 core 1.2.0
PHP version = 4.4.4 cgi
Webserver = Apache/2.0.54 (Unix) PHP/4.4.4 mod_ssl/2.0.54 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.3.2
Database = mysql 5.0.24a-standard-log, lock.system=database
Toolkits = Exif, Ffmpeg, ImageMagick
Acceleration = full/900, full/900
Operating system = Linux milliken 2.6.19.2-grsec+e+f6b+gr219+opt+c5+gr2b-grsec-grsec #1 SMP Mon Feb 12 14:00:45 PST 2007 i686
Default theme = rohjuh
gettext = enabled
Locale = en_US
Browser = Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2
Posts: 100
Well, I finally got this to work, sort of. The rescan seemed to process successfully. However, I was under the impression that the script rescans all aspects of the photo. In this thread, people were primarily interested in batch replacement of existing original photos with larger sized ones. I, on the other hand, want to be able to batch replace existing photos with ones that have a different origination date. A few of my early albums contain scanned photos, the origination dates of which are the date the photo was scanned, not the date the photo was taken. I want to replace all those photos with new photos of the same filenames but with corrected origination dates.
Any suggestions on tweaking the script so that it rescans the origination date?
While the script didn't do what I hoped it would do, the slightly modified script I used may be of use to someone else. What it does is run the rescan script only on a select album. You must know the itemID (same as the g_id in the db) of the album (replace the "1036" with your album's itemID).
<?php header('Content-type: text/plain'); // Load the Gallery API require_once(dirname(__FILE__) . '/embed.php'); $ret = GalleryEmbed::init(array('fullInit' => true)); if ($ret) { echo $ret->getAsText(); exit; } // Grab all the photos $gallery->guaranteeTimeLimit(120); // Load album object (the itemID/g_id of the album) // 1036 is just an example; replace with the itemID/g_id of the album you want to modify list ($ret, $album) = GalleryCoreApi::loadEntitiesById(1036); // rescans the objects in the above album list ($ret, $ids) = GalleryCoreApi::fetchDescendentItemIds($album); if ($ret) { echo $ret->getAsText(); exit; } // Loop the photos echo "Rescanning " . count($ids) . " images\n"; foreach ($ids as $id) { // Load the photo object $gallery->guaranteeTimeLimit(60); list ($ret, $photo) = GalleryCoreApi::loadEntitiesById($id); if ($ret) { echo $ret->getAsText(); exit; } // Find the image, lock it, rescan and save list ($ret, $path) = $photo->fetchPath(); if ($ret) { echo $ret->getAsText(); exit; } echo "Processing '$path'\n"; list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($id); if ($ret) { echo $ret->getAsText(); exit; } $ret = $photo->rescan(); if ($ret) { echo $ret->getAsText(); exit; } $ret = $photo->save(); if ($ret) { echo $ret->getAsText(); exit; } // Free the image lock $ret = GalleryCoreApi::releaseLocks($lockId); if ($ret) { echo $ret->getAsText(); exit; } // Delete all the photo derivatives $ret = GalleryCoreApi::invalidateDerivativeDimensionsBySourceIds(array($id)); if ($ret) { echo $ret->getAsText(); exit; } } // Finish $ret = GalleryEmbed::done(); if ($ret) { echo $ret->getAsText(); exit; } ?>Posts: 7
Hello everyone! I have read all the posts and tried to replace my photos on my server but did nothing. I want to replace the old images with new hi-resolution ones but smart ftp comes up with this message "Transfer failed." although i choose "replace file". I have also CHMOD 777 to my "g2data" and "albums" folders. This rescan.php script seems to work, i mean it doesn't come up with errors or anything, but i cannot replace my files through ftp. Any ideas? Thanks for your time and you replies.
Antonis