MinnPost / minnpost-wordpress

MinnPost.com in WordPress
GNU General Public License v2.0
2 stars 0 forks source link

Icon overlay on member content images #46

Closed jonathanstegall closed 6 years ago

jonathanstegall commented 6 years ago

This is the code Drupal uses:

$node = imagecache_actions_node_from_filepath($image->source, $file_data) ;
$plus_levels = variable_get('minnpost_membercontent_eligible_levels', array('Silver', 'Gold', 'Platinum'));
$icon_style = $node->field_minnpost_plus_icon_style[0]['value'];
$access_levels = array();

foreach ($node->field_minnpost_access as $access_level) {
    $access_levels[] = $access_level['value'];
}

$check = array_intersect($access_levels, $plus_levels);
if (count($check) > 0 && isset($icon_style)) {
    $layer = 'sites/default/themes/siteskin/inc/images/icons/' . $icon_style . '.png';
    if (is_string($layer) ) {
        if (! file_exists($layer)) {
            trigger_error("Image file does not exist. Attempted to overlay $layer", E_USER_ERROR);
            return FALSE;
        }
        $layer = imageapi_image_open($layer);
    }
    // else $layer had better be an image handle
$iconwidth = _imagecache_percent_filter('25%', $image->info['width']);
imageapi_image_scale($layer, $iconwidth);
    $x = $image->info['width'] - $layer->info['width'] - 5;
    $y = 5;
    $x = imagecache_actions_keyword_filter($x, $image->info['width'], $layer->info['width']);
    $y = imagecache_actions_keyword_filter($y, $image->info['height'], $layer->info['height']);
    $alpha = 100;
    $reverse = FALSE;
    return imageapi_toolkit_invoke('overlay', $image, array(&$layer, $x, $y, $alpha, $reverse));
} else {
    return $image;
}

Images to overlay the icon onto in this way:

jonathanstegall commented 6 years ago

https://github.com/MinnPost/wp-post-image-watermarks

At the moment it watermarks the icon onto the above image sizes. This is a big plus.

Things it still needs to do:

  1. put the icon in the right location ✅
  2. scale the icon so it's always the right size on the underlying image ✅
  3. Thumbnail image types: ✅
    • gif ✅
    • png ✅
    • jpg ✅
    • jpeg ✅
  4. Watermark image types:
    • gif
    • png ✅
    • jpg
    • jpeg 4. maybe work with the imagemagick editor as well
jonathanstegall commented 6 years ago

Made a separate issue for if we ever want to support other image types as watermarks. But for now that is not necessary.