(Here I do all the calculations necessary to create the derivative operations, and determine if such a derivative already exists. Example operation string: 'crop|8.75,0,83.125,99.75;scale|250,250')
// There's no matching derivative, so we need to add one
list ($ret, $source) = GalleryCoreApi::fetchPreferredSource($item);
if ($ret)
{
throw new GalleryException('Could not find the source of your image', 'Source of item ' . $item->getId() . ' could not be found: ' . $ret->getAsText());
}
list ($ret, $toolkit, $outputMimeType) = GalleryCoreApi::getToolkitByOperation($source->getMimeType(), 'crop');
if ($ret || !isset($toolkit))
{
throw new GalleryException(null, 'Could not find the crop toolkit for mimetype ' . $source->getMimeType());
}
list ($ret, $newOperations, $newOutputMimeType) = GalleryCoreApi::makeSupportedViewableOperationSequence($outputMimeType, $op);
if ($ret)
{
throw new GalleryException(null, $ret->getAsText());
}
if (!$newOperations || !$newOutputMimeType)
{
$newOperations = $op;
$newOutputMimeType = $outputMimeType;
}
list ($ret, $derivative) = GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $source->getEntityType());
if ($ret || !isset($derivative))
{
throw new GalleryException('Could not create a resize of your photo');
}
$ret = $derivative->create($item->getId(), DERIVATIVE_TYPE_IMAGE_RESIZE);
if ($ret)
{
throw new GalleryException('Could not create a resize of your photo');
}
$derivative->setMimeType($newOutputMimeType);
$derivative->setDerivativeOperations($newOperations);
$derivative->setDerivativeSourceId($source->getId());
$ret = $derivative->save();
if ($ret)
{
throw new GalleryException('Could not create a resize of your photo', 'Could not save resize: ' . $ret->getAsText());
}
Posts: 10
I should have really checked out my previous problem with getting groups sync'd - same thing! Wasn't calling GalleryEmbed::done(); Now I have working automatic crop and scale!