[BUGFIX] FAL: Image Processing doesn't respect GFX "thumbnails_png"
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Processing / AbstractGraphicalTask.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Processing;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Andreas Wolf <andreas.wolf@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use \TYPO3\CMS\Core\Resource, \TYPO3\CMS\Core\Utility;
31
32 /**
33 * Abstract base implementation of a task.
34 *
35 * If you extend this class, make sure that you redefine the member variables $type and $name
36 * or set them in the constructor. Otherwise your task won't be recognized by the system and several
37 * things will fail.
38 *
39 */
40 abstract class AbstractGraphicalTask extends AbstractTask {
41
42 /**
43 * @var string
44 */
45 protected $targetFileExtension;
46
47 /**
48 * Sets parameters needed in the checksum. Can be overridden to add additional parameters to the checksum.
49 * This should include all parameters that could possibly vary between different task instances, e.g. the
50 * TYPO3 image configuration in TYPO3_CONF_VARS[GFX] for graphic processing tasks.
51 *
52 * @return array
53 */
54 protected function getChecksumData() {
55 return array_merge(
56 parent::getChecksumData(),
57 array(serialize($GLOBALS['TYPO3_CONF_VARS']['GFX']))
58 );
59 }
60
61 /**
62 * Returns the name the processed file should have
63 * in the filesystem.
64 *
65 * @return string
66 */
67 public function getTargetFilename() {
68 return $this->getSourceFile()->getNameWithoutExtension()
69 . '_' . $this->getConfigurationChecksum()
70 . '.' . $this->getTargetFileExtension();
71 }
72
73 /**
74 * Determines the file extension the processed file
75 * should have in the filesystem.
76 *
77 * @return string
78 */
79 public function getTargetFileExtension() {
80 if (!isset($this->targetFileExtension)) {
81 $this->targetFileExtension = $this->determineTargetFileExtension();
82 }
83
84 return $this->targetFileExtension;
85 }
86
87 /**
88 * Gets the file extension the processed file should
89 * have in the filesystem by either using the configuration
90 * setting, or the extension of the original file.
91 *
92 * @return string
93 */
94 protected function determineTargetFileExtension() {
95 if (!empty($this->configuration['fileExtension'])) {
96 $targetFileExtension = $this->configuration['fileExtension'];
97 } else {
98 // explanation for "thumbnails_png"
99 // Bit0: If set, thumbnails from non-jpegs will be 'png', otherwise 'gif' (0=gif/1=png).
100 // Bit1: Even JPG's will be converted to png or gif (2=gif/3=png)
101
102 $targetFileExtensionConfiguration = $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'];
103 if ($this->getSourceFile()->getExtension() === 'jpg') {
104 if ($targetFileExtensionConfiguration == 2) {
105 $targetFileExtension = 'gif';
106 } elseif ($targetFileExtensionConfiguration == 3) {
107 $targetFileExtension = 'png';
108 } else {
109 $targetFileExtension = 'jpg';
110 }
111 } else {
112 // check if a png or a gif should be created
113 if ($targetFileExtensionConfiguration == 1 || $this->getSourceFile()->getExtension() === 'png') {
114 $targetFileExtension = 'png';
115 } else {
116 // thumbnails_png is "0"
117 $targetFileExtension = 'gif';
118 }
119 }
120 }
121
122 return $targetFileExtension;
123 }
124
125 }
126
127 ?>