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
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Tue, 2006-01-03 21:25

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.

Login or register to post comments
samuurai

Joined: 2006-01-03
Posts: 15
Posted: Wed, 2006-01-04 10:58

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

Login or register to post comments
samuurai

Joined: 2006-01-03
Posts: 15
Posted: Wed, 2006-01-04 11:21

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.

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Wed, 2006-01-04 15:40

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

Login or register to post comments
samuurai

Joined: 2006-01-03
Posts: 15
Posted: Wed, 2006-01-04 22:18

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

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Wed, 2006-01-04 22:40

heh, you need to add

<?php

at the top and

?>

at the end. else it's not recognized as php code.

Login or register to post comments
samuurai

Joined: 2006-01-03
Posts: 15
Posted: Wed, 2006-01-04 23:09

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

Login or register to post comments
samuurai

Joined: 2006-01-03
Posts: 15
Posted: Wed, 2006-01-04 23: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

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Wed, 2006-01-04 23:28

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.

Login or register to post comments
samuurai

Joined: 2006-01-03
Posts: 15
Posted: Wed, 2006-01-04 23:44

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.

Login or register to post comments
chromatest
chromatest's picture

Joined: 2005-10-03
Posts: 5
Posted: Mon, 2006-01-16 23:41

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)

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Tue, 2006-01-17 02:32

delete the db cache (site admin -> maintenance | or http://gallery.chromatest.net/lib/support/ -> cache)

Login or register to post comments
chromatest
chromatest's picture

Joined: 2005-10-03
Posts: 5
Posted: Thu, 2006-01-19 21:40

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.

Login or register to post comments
aidanlister

Joined: 2005-12-07
Posts: 55
Posted: Thu, 2006-02-23 05:08

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.

Login or register to post comments
djonest

Joined: 2006-03-28
Posts: 16
Posted: Tue, 2006-03-28 23:55

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

Login or register to post comments
djonest

Joined: 2006-03-28
Posts: 16
Posted: Fri, 2006-03-31 22:42

bump

Login or register to post comments
aidanlister

Joined: 2005-12-07
Posts: 55
Posted: Sat, 2006-04-01 02:04

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;
}

?>
Login or register to post comments
djonest

Joined: 2006-03-28
Posts: 16
Posted: Sat, 2006-04-01 09:11

That worked a treat! You're a star, thank you!

Login or register to post comments
afatac

Joined: 2006-02-05
Posts: 47
Posted: Wed, 2006-05-24 08:23

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)

Login or register to post comments
ladykathleen

Joined: 2006-06-17
Posts: 1
Posted: Sun, 2006-07-09 19:00

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

Login or register to post comments
gregoryx

Joined: 2006-04-27
Posts: 8
Posted: Sun, 2006-11-05 21:03

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.
In the mean time (before I screw things up :)), 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?

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?

Login or register to post comments
geofflee

Joined: 2006-11-24
Posts: 1
Posted: Fri, 2006-11-24 12:11

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---

<?php
/**
 * Note that this is independent of Gallery, and you will still need to apply a
 * PHP script to rescan all the images. (see: http://gallery.menalto.com/node/42333)
 * 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.
 *
 * @see http://gallery.menalto.com/node/42333
 * @author Geoffrey Lee <geoffreyj.lee NO@SPAM gmail.com>
 */

// Prevent the script from auto aborting if it runs for a long time
if (ini_get('safe_mode')) {
	echo "Safe mode is active. Cannot proceed!";
	exit();
}
set_time_limit(0);

/**
 * Swap the contents of two variables.
 *
 * @param $var1
 * @param $var2
 */
function swap(&$var1, &$var2)
{
	$temp = $var1;
	$var1 = $var2;
	$var2 = $var1;
}

/**
 * Resize an image to fit within the specified max width and max height.
 *
 * Since images can come in either portrait or landscape, $allowRotation specifies
 * whether to swap the max width and max height when determining if the image
 * needs to be resized.
 *
 * This function currently supports JPEG, GIF, and PNG. It will simply do nothing
 * when applied to a non-image or unsupported file. An optional $quality
 * parameter allows you to set the image quality (0-100) for JPEG images.
 *
 * @author Geoffrey Lee <geoffreyj.lee NO@SPAM gmail.com>
 * @param string $filename
 * @param int $maxWidth
 * @param int $maxHeight
 * @param boolean $allowRotation
 * @param int $quality
 */
function shrinkImage($filename, $maxWidth, $maxHeight, $allowRotation = false, $quality = 75)
{
	// Don't allow this operation to be interrupted
	$user_abort_option = ignore_user_abort(true);
	
	if (file_exists($filename) && is_file($filename)) {
		// Get width, height, and mime type
		$imageInfo = getImageSize($filename);
		if ($imageInfo) {
			list($oldWidth, $oldHeight) = $imageInfo;
			$mime = $imageInfo['mime'];
		} else {
			$mime = "unknown";
		}
		
		// Load the image
		switch ($mime) {
		case 'image/gif':
			$sourceImage = imageCreateFromGIF($filename);
			break;
		case 'image/jpeg':
			$sourceImage = imageCreateFromJPEG($filename);
			break;
		case 'image/png':
			$sourceImage = imageCreateFromPNG($filename);
			break;
		default:
			echo "<strong>$filename</strong> of type $mime is unsupported<br />\r\n";
		}
				
		// Perform resize
		if (isset($sourceImage)) {
			// Determine if our image is portrait or landscape
			if ($allow_rotation && $oldHeight > $oldWidth) {
				swap($maxWidth, $maxHeight);
			}
			
			// Determine the percent to resize by
			$percentWidth = $maxWidth / $oldWidth;
			$percentHeight = $maxHeight / $oldHeight;
			$percentResize = $percentWidth > $percentHeight ? $percentHeight : $percentWidth;
			
			// We only want to shrink images that are too large
			if ($percentResize < 1) {
				// Perform the resize
				$newWidth = $oldWidth * $percentResize;
				$newHeight = $oldHeight * $percentResize;
				$destinationImage = imageCreateTrueColor($newWidth, $newHeight);
				imageCopyResampled($destinationImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
				
				// Save the new image
				if ($destinationImage) {
					switch ($mime) {
					case 'image/gif':
						$saved = imageGIF($destinationImage, $filename);
						break;
					case 'image/jpeg':
						$saved = imageJPEG($destinationImage, $filename, $quality);
						break;
					case 'image/png':
						$saved = imagePNG($destinationImage, $filename);
						break;
					default:
						echo "Could not save $filename because type $mime is unsupported<br />\r\n";
						$saved = false;
					}
				}
				
				if ($saved) {
					echo sprintf("Resizing <strong>%s</strong> of size %dx%d and type %s to size %dx%d<br />\r\n",
						$filename, $oldWidth, $oldHeight, $mime, $newWidth, $newHeight);
				}
			} else {
				echo sprintf("Skipping <strong>%s</strong> of size %dx%d<br />\r\n", $filename, $oldWidth, $oldHeight);
			}
			
			// Perform clean up
			if (isset($destinationImage)) imageDestroy($destinationImage);
			if (isset($sourceImage)) imageDestroy($sourceImage);
		}
	} else {
		echo sprintf("Skipping $filename<br />\r\n");
	}
	
	// Restore previous setting
	ignore_user_abort($user_abort_option);
}

/**
 * This applies the shrinkImage() function on all the files within the current
 * directory, and then calls resizeTree() on each of the subdirectories. The
 * starting directory is set by the $thisDirectory parameter, which otherwise
 * defaults to the directory in which this file is placed.
 *
 * Note that this function may take a very long time to execute if you have a
 * lot of images!
 *
 * Also note that by default, max width and max height are swapped for portrait
 * images!
 *
 * @author Geoffrey Lee <geoffreyj.lee NO@SPAM gmail.com>
 * @param int $maxWidth
 * @param int $maxHeight
 * @param string $thisDirectory
 * @param boolean $allowRotation
 */
function resizeTree($maxWidth, $maxHeight, $thisDirectory = '.', $allowRotation = true)
{
	// List the current directory
	$currentDirectory = dir($thisDirectory);
	$directories = array();
	$files = array();
	while ($item = $currentDirectory->read()) {
		if ($item == '.' || $item == '..') {
			continue;
		} else if (is_dir($thisDirectory . '/' . $item)) {
			$directories[] = $thisDirectory . '/' . $item;
		} else {
			$files[] = $thisDirectory . '/' . $item;
		}
	}
	$currentDirectory->close();
	
	// Resize all the files
	foreach ($files as $file) {
		shrinkImage($file, $maxWidth, $maxHeight, $allowRotation, 75);
	}
	unset($files);
	
	// Recurse through each subdirectory
	foreach ($directories as $directory) {
		resizeTree($maxWidth, $maxHeight, $directory);
	}
	unset($directories);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>Resizing script</title>
</head>

<body>
<?php
resizeTree(1280, 1024, '/home/myAccountName/g2data/albums', true);
?>
</body>

</html>
Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Fri, 2006-11-24 16:23

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.

Login or register to post comments
jimbutler

Joined: 2005-09-12
Posts: 1
Posted: Sun, 2007-01-28 20:05

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";
?>

Login or register to post comments
rogermh

Joined: 2005-01-09
Posts: 100
Posted: Mon, 2007-03-19 15:40

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?

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32168
Posted: Mon, 2007-03-19 17:16

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

Login or register to post comments
rogermh

Joined: 2005-01-09
Posts: 100
Posted: Mon, 2007-03-19 17:53

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);

Login or register to post comments
rogermh

Joined: 2005-01-09
Posts: 100
Posted: Tue, 2007-03-20 16:31

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

Login or register to post comments
rogermh

Joined: 2005-01-09
Posts: 100
Posted: Wed, 2007-03-21 07:48

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;
}

?>
Login or register to post comments
atzounis

Joined: 2007-06-25
Posts: 7
Posted: Sat, 2007-07-14 08:20

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

Login or register to post comments