aboutsummaryrefslogtreecommitdiffstats
path: root/include/derivative.inc.php
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2013-11-17 10:10:05 +0000
committermistic100 <mistic@piwigo.org>2013-11-17 10:10:05 +0000
commit8e0f55043f7d970bc6ab3ba7e8638d16d6de6102 (patch)
treed5436647386c65b5eac1596cbb80b401fd7634da /include/derivative.inc.php
parentab3c27871e8e0db98dafac36df091f082899e949 (diff)
add DerivativeImage::get_one method working like DerivateImage::get_all but returning only one size
git-svn-id: http://piwigo.org/svn/trunk@25504 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/derivative.inc.php51
1 files changed, 45 insertions, 6 deletions
diff --git a/include/derivative.inc.php b/include/derivative.inc.php
index 1625d5860..6821817fe 100644
--- a/include/derivative.inc.php
+++ b/include/derivative.inc.php
@@ -192,13 +192,22 @@ final class DerivativeImage
}
/**
- @return an associative array of derivative images with keys all standard derivative image types:
- Disabled derivative types can be still found in the return mapped to an enabled derivative (e.g. the values are not
- unique in the return array). This is useful for any plugin/theme to just use $deriv[IMG_XLARGE] even if the XLARGE is
- disabled.
- */
+ * Return associative an array of all DerivativeImage for a specific image.
+ * Disabled derivative types can be still found in the return mapped to an
+ * enabled derivative (e.g. the values are not unique in the return array).
+ * This is useful for any plugin/theme to just use $deriv[IMG_XLARGE] even if
+ * the XLARGE is disabled.
+ *
+ * @param array|SrcImage $src_image array of info from db or SrcImage
+ * @return DerivativeImage[]
+ */
static function get_all($src_image)
{
+ if (!is_object($src_image))
+ {
+ $src_image = new SrcImage($src_image);
+ }
+
$ret = array();
// build enabled types
foreach (ImageStdParams::get_defined_type_map() as $type => $params)
@@ -206,7 +215,7 @@ final class DerivativeImage
$derivative = new DerivativeImage($params, $src_image);
$ret[$type] = $derivative;
}
- // disabled types fqllbqck to enqbled types
+ // disabled types, fallback to enabled types
foreach (ImageStdParams::get_undefined_type_map() as $type => $type2)
{
$ret[$type] = $ret[$type2];
@@ -215,6 +224,36 @@ final class DerivativeImage
return $ret;
}
+ /**
+ * Returns an instance of DerivativeImage for a specific image and size.
+ * Disabled derivatives fallback to an enabled derivative.
+ *
+ * @param string $type
+ * @param array|SrcImage $src_image array of info from db or SrcImage
+ * @return DerivativeImage|null null if $type not found
+ */
+ static function get_one($type, $src_image)
+ {
+ if (!is_object($src_image))
+ {
+ $src_image = new SrcImage($src_image);
+ }
+
+ $defined = ImageStdParams::get_defined_type_map();
+ if (isset($defined[$type]))
+ {
+ return new DerivativeImage($defined[$type], $src_image);
+ }
+
+ $undefined = ImageStdParams::get_undefined_type_map();
+ if (isset($undefined[$type]))
+ {
+ return new DerivativeImage($defined[ $undefined[$type] ], $src_image);
+ }
+
+ return null;
+ }
+
private static function build($src, &$params, &$rel_path, &$rel_url, &$is_cached=null)
{
if ( $src->has_size() && $params->is_identity( $src->get_size() ) )