The code outputs and does exactly what I intend it to do, but it throws the following notices:
Warning: Illegal string offset 'effects' in image_style_create_derivative() (line 928 of /var/www/html/modules/image/image.module). Warning: Invalid argument supplied for foreach() in image_style_create_derivative() (line 928 of /var/www/html/modules/image/image.module).
The code I am using is so:
(Builds the actual image style from base uri if the file doesn't currently exist)
/**
* Check for and generate image derivatives if none exist.
*
* @param string $style
* Image style to check.
* @param string $uri
* URI of the base image.
*
* @return false|string
* Returns uri for the image that should now exist.
*/
function _srv_image_derivitives($style, $uri) {
// So I have something to return.
$final_uri = image_style_path($style, $uri);
// Gets the absolute file name to the file to check for.
$filename = drupal_realpath($final_uri);
// If it's not there, make it there.
if (!file_exists($filename)) {
$style_load = image_style_load($style);
if (count($style_load)) {
image_style_create_derivative(
$style,
$uri,
image_style_path(
$style,
$uri
)
);
}
}
return $final_uri;
}
(Builds an array of images that will be converted to a json array for an rest post)
/**
* Build derivatives array from base image uri.
*
* @param string $image_uri
* The base image to construct.
*
* @return array
* Array of image derivatives.
*/
function _srv_build_derivative_array($image_uri) {
// Set up the image styles to be used.
$image_styles = array(
'carousel',
'rotator',
'leadlandscape',
'focus',
'linkthumbnail',
'topstorythumbnail',
'topnavthumbnail',
'lateststoriesthumbnail',
'headline',
'subcategorylead',
'opinionlead',
'entertainmentlead',
'entertainmentlatestthumbnail',
'gallerylandscape',
'gallerythumbnail',
'reporterstory',
'galleryportrait',
);
$images_array = array();
foreach ($image_styles as $key_one => $style) {
$image_style_uri = _srv_image_derivitives($style, $image_uri);
// EFS path instead of public:// uri.
$images_array[$style] = str_replace("public://", "/data/sites_default_files/", $image_style_uri);
}
return $images_array;
}
$style
before passing toimage_style_create_derivative()
function. From error it seems that the$style
doesn't has effects key in it. Also check if this is for all image styles or only for few, if only for few check if those image styles has any effect added into them$style
variable into watchdog and check if it has effects key in it.