Drupal7 only. I was just thinking about the following. A lot of people want to restrict access to thei high resolution images so they chose private but the also show small thumbnails to the public.
If you chose private all thumbnails will be private to causing bootstrap-galore on for example, gallery pages with 30 thumbs.
So the idea was to somehow create an image style that can be applied to save a chose preset (for example thumbnails) in private while saving the rest of the full resolution presets in private.
This somehow is a first attempt, not working, not final, only showing the idea.
<?php
/**
* Implements hook_file_url_alter().
*/
function image_optimize_file_url_alter(&$url) {
//xdebug this
//private bootstraps for every file
//second time uri is puclic and this code will be skipped...
// Only apply to private files
//if (strpos($url, 'private://styles') !== FALSE) {
// Find out the used image style.
preg_match('/styles\/(?P<style>\w+)\/private/i', $url, $match);
if (!empty($match['style'])) {
$style = $match['style'];
// Look whether this special effect is stored in the image style
$image_style = image_style_load($style);
$optimize = FALSE;
foreach ($image_style['effects'] as $effect) {
if ($effect['module'] == 'image_optimize') {
$optimize = TRUE;
break;
}
}
// If yes rewrite the url
if ($optimize) {
// Find the url behind private://
// @todo: Wouldn't a str_replace private:// be much easier here?
preg_match('/(\w+):\/\/(.+)/i', $url, $match1);
if (!empty($match1[2])) {
$url = 'public://' . $match1[2];
}
}
}
//}
}
function image_optimize_image_effect_info() {
$effects = array();
$effects['test'] = array(
'label' => t('Test'),
'help' => t('TODO'),
'effect callback' => 'image_optimize_effect',
'form callback' => 'image_optimize_effect_form',
'summary theme' => 'image_optimize_effect_summary_theme',
);
return $effects;
}
function image_optimize_effect() {
}
function image_optimize_effect_form() {
}
function image_optimize_effect_summary_theme() {
}
Another thing i am asking myself is if that url altering really saves bootstraps.
Any opinions, suggestions?