[Checkout] download images in different formats

kroyeren
kroyeren's picture

Joined: 2012-07-19
Posts: 8
Posted: Thu, 2012-07-19 11:07

Hi

I'm working with a gallery 2.3 installation with checkout and checkout-download modules installed. We're quite happy about it, but there's one option we seem to be missing. We would like our customers to be able to download images in different formats; either a tif or a jpg. We still wan't them to do it via ckeckout's cart and as a zip catalogue.
It seems like it's not possible at the moment, so what would be the right approach; should I try to extend/modify the download module or should I fork it and make the changes. Can't seem to find the right place for feature-requests.

Kind Regards

Morten

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Thu, 2012-07-19 11:36

A customization like that you'd have to do yourself. (or hire it out)
Gallery currently does not support derivatives of different mime types.
But it has been done.
In the transcode module we create a new derivative of a different mime:

list($ret, $derivative) = GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $source->getEntityType());
if ($ret) {
    return array($ret, null, null, null);
}
if (!isset($derivative)) {
    return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT), null, null, null);
}
// We don't have a DERIVATIVE_TYPE for what you're doing to we'll use resize.
$ret = $derivative->create($source->getId(), DERIVATIVE_TYPE_IMAGE_RESIZE);
if ($ret) {
    return array($ret, null, null, null);
}
$derivative->setMimeType($mime);
$derivative->setDerivativeOperations(/*here you chain your image operations like flip.scale.rotate and output*/'convert-to-'.$mime);
$derivative->setDerivativeSourceId($source->getId());
$ret = $derivative->save();
if ($ret) {
    return array($ret, null, null, null);
}

list($ret) = GalleryCoreApi::rebuildDerivativeCacheIfNotCurrent($derivative->getId());
if ($ret) {
    return array($ret, null, null);
}

and then later for presentation - or in your case zip/download - we fetch all derivatives and loop through them for the derivative w/ the proper mimeType and deliver.

You have to make sure you have a supporting toolkit to create all your mime types - ImageMagick can handle most.

@see http://codex.gallery2.org/Gallery2:API

-s

 
kroyeren
kroyeren's picture

Joined: 2012-07-19
Posts: 8
Posted: Thu, 2012-07-19 12:04
suprsidr wrote:
A customization like that you'd have to do yourself. (or hire it out)
-s

Well, the company did hire it out... to me ;-)

Thanks for the info, I'll look into it.

Maybe I should just have it working before bothering on how to submit anything back...

 
kroyeren
kroyeren's picture

Joined: 2012-07-19
Posts: 8
Posted: Tue, 2012-07-31 08:54

So, I've found out that Gallery actually does support converting images to different formats...

getToolKitByOperation('convert-to-'.$desiredMimeType); 
$toolkit->perfomOperation([lot of options]);

I have made a working solution for my client, but I recon it would be appropriate to submit it back as a patch for checkout download. For it to be usable in general I need to make some adjustments, though

Is there a way to get a list of supported mimetypes by all the image toolkits that are installed on a given system (some kind of "getSupportedMimeTypes()" operation)

Also the convertMimeToExtensions seem to be giving extensions back in a rather unstructured way depending on the mime.
Eg. image/jpeg gives {jpg, jpeg, jpe} and image/tiff gives {tiff, tif}. I would like to use a 3-letter extension to be on the safe-side, so maybe the order could be standardized for all mime-types (eg. {common-3-letter, common-4-letter[,other]}.

/morten

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2012-07-31 12:08
Quote:
Is there a way to get a list of supported mimetypes by all the image toolkits that are installed on a given system (some kind of "getSupportedMimeTypes()" operation)

the thumbnail module does that
@see modules/thumbnail/classes/ThumbnailHelper.class getMimeTypeMap

Quote:
I would like to use a 3-letter extension to be on the safe-side, so maybe the order could be standardized for all mime-types

Gallery uses these two methods to convert back and forth
http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html#methodconvertExtensionToMime
http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html#methodconvertMimeToExtensions

and you can edit which extensions and what order with the MIME Maintenance module. Gallery Admin -> MIME Types

-s

 
kroyeren
kroyeren's picture

Joined: 2012-07-19
Posts: 8
Posted: Wed, 2012-08-01 06:57

Thanks again.

I did find the MIME Types module, that obviously also gets a map of supported MIME-types.
Wouldn't the recommended method be to use the GalleryCoreApi::getMapEntry method rather than creating a database-query?

Editing the mime-types doesn't seem to have any effect on what order the extensions are listed. The image/tiff type have extentions tiff and tif. Even if I delete tiff and add it again afterwards, it's still first in the list.

However, I don't think it's a viable solution for a module to depend on a gallery administrator to type the extensions in the right order. That would just break the module in too many cases. A better solution would probably be to search the extension array for the first 3-letter extension. Or should I just take the first? Doesn't most systems support 4-letter extensions these days? I'm mostly linux user, so I'm not sure about this...

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2012-08-01 12:26
Quote:
Wouldn't the recommended method be to use the GalleryCoreApi::getMapEntry method rather than creating a database-query?

both build a query.
but ThumbnailHelper::getMimeTypeMap does exactly what you want.

and other ThumbnailHelper methods can be useful too ThumbnailHelper::fetchToolkitSupport

You could either duplicate these methods to remove dependencies or require the thumbnail module be present.

-s