added missing module fixer and updated imagecache_actions

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-21 17:06:08 +01:00
parent 3f7e130321
commit 0bcc558ed5
83 changed files with 6386 additions and 2517 deletions

View File

@@ -1,16 +1,13 @@
name = Imagecache Autorotate
description = Autorotate image based on EXIF Orientation.
description = Provides an image effect to autorotate an image based on EXIF data.
package = Media
core = 7.x
dependencies[] = image
files[] = imagecache_autorotate.install
files[] = imagecache_autorotate.module
; Information added by drupal.org packaging script on 2012-12-04
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2018-03-20
version = "7.x-1.9"
core = "7.x"
project = "imagecache_actions"
datestamp = "1354653754"
datestamp = "1521550387"

View File

@@ -1,13 +1,25 @@
<?php
/**
* @file (un)install and (dis/en)able hooks for imagecache autorotate module.
* Implements hook_requirements().
*/
/**
* Implements hook_enable().
*/
function imagecache_autorotate_enable() {
if (!function_exists('exif_read_data')) {
drupal_set_message(t('The exif_read_data() function is not available in this PHP installation. You probably will have to enable the exif extension.'), 'warning');
function imagecache_autorotate_requirements($phase) {
$result = array();
$t = get_t();
if (!extension_loaded('exif')) {
$result['imagecache_autorotate_exif_extension'] = array(
'title'=> 'EXIF extension',
'value'=> $phase === 'runtime' ? $t('Disabled') : '',
'description'=> $t('The autorotate image effect requires the exif extension to be enabled.'),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$result['imagecache_autorotate_exif_extension'] = array(
'title'=> 'EXIF extension',
'value'=> $t('Enabled'),
'severity' => REQUIREMENT_OK,
);
}
return $result;
}

View File

@@ -1,61 +1,71 @@
<?php
/**
* @file
* Autorotate image based on EXIF Orientation tag.
* http://sylvana.net/jpegcrop/exif_orientation.html
* @file Autorotate image based on EXIF Orientation tag.
*
* This mini-module contributed by jonathan_hunt http://drupal.org/user/28976
* EXIF: https://en.wikipedia.org/wiki/Exchangeable_image_file_format
* EXIF orientation tag: http://sylvana.net/jpegcrop/exif_orientation.html
*
* Originally contributed by jonathan_hunt https://drupal.org/user/28976,
* September 1, 2009
*/
/**
* Implements hook_image_effect_info().
*
* Tweaked by dman to add documentation
* Defines information about the supported effects.
*/
/* In Adobe PNGs and TIFF, this information MAY be present in the XMP
* metadata like so:
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
<tiff:Orientation>6</tiff:Orientation>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
*/
function imagecache_autorotate_image_effect_info() {
$effects = array();
$effects['imagecache_autorotate'] = array(
'label' => t('Autorotate'),
'help' => t('Add autorotate image based on EXIF Orientation.'),
'effect callback' => 'imagecache_autorotate_image',
'help' => t('Autorotate image based on EXIF orientation and reset that tag.'),
'effect callback' => 'imagecache_autorotate_effect',
'dimensions callback' => 'imagecache_autorotate_dimensions',
'form callback' => 'imagecache_autorotate_form',
'summary theme' => 'imagecache_autorotate_summary',
);
return $effects;
}
/**
* @todo: This form is no longer needed nor defined in the hook above. If this
* information still needs to be displayed it should probably be moved to help.
* Implements hook_theme().
*
* Registers theme functions for the effect summaries.
*/
function imagecache_autorotate_theme() {
return array(
'imagecache_autorotate_summary' => array(
'variables' => array('data' => NULL),
),
);
}
/**
* Builds the auto-rotate form.
*
* This effect has no options, only some help text, so the form is displayed
* anyway.
*/
function imagecache_autorotate_form() {
$form = array();
$form['help'] = array(
'#type' => 'markup',
'#value' => "<p>
<b>There are no user-configurable options for this process.</b>
</p><p>
Certain cameras can embed <em>orientation</em> information into image
'#markup' => "<p><strong>There are no user-configurable options for this process.</strong></p>
<p>Certain cameras can embed <em>orientation</em> information into image
files when they save them. This information is embedded in an EXIF tag
and can be used to rotate images to their correct position for display.
</p><p>
<em>Not all cameras or images contain this information.</em>
This process is only useful for those that do.
</p><p>
The expected/supported values are
<br/><strong>Tag</strong>: <code>0x0112 Orientation</code>
This process is only useful for images that contain this information,
whereas for other images it is harmless.
</p>
<p>Although most modern browsers do support the orientation tag, the
information may get lost or become incorrect by other operations.
So, to support all browsers and prevent rotation errors, it is better to
start each image style with this effect.
</p>
<p>The expected/supported values are:<br/>
<strong>Tag</strong>: <code>0x0112 Orientation</code>
</p>
<ul>
<li>1 = Horizontal (normal)</li>
@@ -63,83 +73,172 @@ function imagecache_autorotate_form() {
<li>6 = Rotate 90 CW</li>
<li>8 = Rotate 270 CW</li>
</ul>
<p>
<a href='http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html'>
EXIF Reference</a>
</p>
<p>Wikipedia: <a href='https://en.wikipedia.org/wiki/Exchangeable_image_file_format'>Exchangeable image file format</a></p>
",
);
return $form;
}
/**
* Autorotate image based on EXIF Orientation tag.
* Implements theme_hook() for the autorotate effect summary.
*
* See code at
* http://sylvana.net/jpegcrop/exif_orientation.html
* param array $variables
* An associative array containing:
* - data: The current configuration for this image effect.
*
* and reference at
* http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
*
* @todo:
* Add horizontal and vertical flips etc.
* Need to create sample set for tests.
* @return string
* The HTML for the summary of this image effect.
* @ingroup themeable
*/
function imagecache_autorotate_image($image, $data) {
// Test to see if EXIF is supported for image type (e.g. not PNG).
if ($image->info['mime_type'] == 'image/jpeg') {
if (!function_exists('exif_read_data')) {
watchdog('image', 'The image %file could not be auto-rotated because the exif_read_data() function is not available in this PHP installation. You probably will have to enable the exif extension.', array('%file' => $image->source));
return FALSE;
}
$exif = exif_read_data(drupal_realpath($image->source));
if (isset($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$degrees = 180;
break;
case 6:
$degrees = 90;
break;
case 8:
$degrees = 270;
break;
default:
$degrees = 0;
}
if ($degrees != 0) {
$org_width = $image->info['width'];
$org_height = $image->info['height'];
image_rotate($image, $degrees);
if (($degrees === 90 || $degrees === 270) && $image->info['width'] === $org_width) {
// The toolkit failed to alter the dimensions (imagemagick currently
// fails to do so). So we do it ourselves.
$image->info['width'] = $org_height;
$image->info['height'] = $org_width;
}
}
}
function theme_imagecache_autorotate_summary(/*array $variables*/) {
return 'image based on its EXIF data.';
}
/**
* Autorotate image based on EXIF Orientation tag.
*/
function imagecache_autorotate_effect(stdClass $image /*, $data*/) {
// Test to see if EXIF is supported by the current image type.
if (in_array($image->info['mime_type'], array('image/jpeg', 'image/tiff'))) {
// Hand over to toolkit.
return image_toolkit_invoke('imagecache_autorotate', $image);
}
else if ($image->source === 'modules/image/sample.png' && !function_exists('exif_read_data')) {
// Issue a warning if we are in the admin screen and the exif extension is
// not enabled.
drupal_set_message(t('The exif_read_data() function is not available in this PHP installation. You probably will have to enable the exif extension.'), 'warning');
else if ($image->source === 'modules/image/sample.png' && user_access('administer image styles')) {
if (!extension_loaded('exif')) {
// Issue a warning if we are in the admin screen and the exif extension is
// not enabled.
drupal_set_message(t('The autorotate image effect requires the exif extension to be enabled.'), 'warning');
if ($image->toolkit === 'imagemagick') {
drupal_set_message(t('Though imagemagick will work without the exif extension, subsequent effects may fail as the image dimensions cannot be updated.'), 'warning');
}
}
}
return TRUE;
}
/**
* Image dimensions callback; Auto-rotate.
* GD toolkit specific implementation of this image effect.
*
* @param stdClass $image
*
* @return bool
* true on success, false otherwise.
*/
function image_gd_imagecache_autorotate(stdClass $image) {
if (!function_exists('exif_read_data')) {
watchdog('imagecache_actions', 'Image %file could not be auto-rotated: !message', array('%file' => $image->source, '!message' => t('The exif_read_data() function is not available in this PHP installation. You probably have to enable the exif extension.')));
return FALSE;
}
// Read and check result.
$exif = @exif_read_data(drupal_realpath($image->source));
if ($exif === FALSE && $image->extension === 'jpg') {
watchdog('imagecache_actions', 'Image %file could not be auto-rotated: !message', array('%file' => $image->source, '!message' => t('The exif_read_data() function returned FALSE.')));
return FALSE;
}
if (isset($exif['Orientation'])) {
// http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html:
// 1 = Horizontal (normal)
// 2 = Mirror horizontal
// 3 = Rotate 180
// 4 = Mirror vertical
// 5 = Mirror horizontal and rotate 270 CW
// 6 = Rotate 90 CW
// 7 = Mirror horizontal and rotate 90 CW
// 8 = Rotate 270 CW
// @todo: Add horizontal and vertical flips etc.
// imagecopy seems to be able to mirror, see conmments on
// http://php.net/manual/en/function.imagecopy.php
// @todo: Create sample set for tests.
switch ($exif['Orientation']) {
case 3:
$degrees = 180;
break;
case 6:
$degrees = 90;
break;
case 8:
$degrees = 270;
break;
default:
$degrees = 0;
}
if ($degrees != 0) {
return image_rotate($image, $degrees);
}
}
return TRUE;
}
/**
* Imagemagick toolkit specific implementation of this image effect.
*
* @param stdClass $image
* An image object.
*
* @return bool
* true on success, false otherwise.
*
* @see http://www.imagemagick.org/script/command-line-options.php#auto-orient
*/
function image_imagemagick_imagecache_autorotate(stdClass $image) {
// Use the exif extension, if enabled, to figure out the new dimensions.
// Moreover (see [#2366163]): to prevent a bug in IM to incorrectly rotate the
// image when it should not, we only pass the auto-orient argument when the
// exif extension could detect the 'Orientation' tag.
if (function_exists('exif_read_data')) {
$exif = @exif_read_data(drupal_realpath($image->source));
if (isset($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 1:
// Normal orientation: no need to rotate or to change the dimensions.
break;
case 5:
case 6:
case 7:
case 8:
// 90 or 270 degrees rotation (+ optional mirror): swap dimensions.
$image->ops[] = '-auto-orient';
$tmp = $image->info['width'];
$image->info['width'] = $image->info['height'];
$image->info['height'] = $tmp;
break;
default:
// All other orientations: pass the arguments, but the dimensions
// remain the same.
$image->ops[] = '-auto-orient';
break;
}
}
elseif ($exif === FALSE && $image->extension === 'jpg') {
watchdog('imagecache_actions', 'Image %file could not be auto-rotated: !message', array('%file' => $image->source, '!message' => t('The exif_read_data() function returned FALSE.')));
}
}
else {
// We do add the auto-orient argument to IM. IM will determine itself
// whether to rotate or not.
$image->ops[] = '-auto-orient';
// However we cannot keep track of the dimensions anymore.
if ($image->info['width'] !== $image->info['height']) {
$image->info['width'] = $image->info['height'] = NULL;;
}
}
return TRUE;
}
/**
* Image dimensions callback for this image effect.
*
* @param array $dimensions
* An array with the dimensions (in pixels) to be modified.
* @param array $data
* An array of parameters for the autorotate effect (empty for this effect).
*/
function imagecache_autorotate_dimensions(array &$dimensions, array $data) {
* param array $data
* An associative array containing the effect data.
*/
function imagecache_autorotate_dimensions(array &$dimensions/*, array $data*/) {
// We can only know the resulting dimensions if both dimensions are equal.
// Otherwise we need to inspect the image itself, which is not passed in here.
// (this callback was introduced to enhance performance by not accessing the
// (this callback was introduced to enhance performance by NOT accessing the
// image file when rendering the width and height attributes of the html img
// tag).
if ($dimensions['width'] !== $dimensions['height']) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB