86f6124cd25a6db57b25527e166a32999db2b986
[core.git] / framework / main / classes / images / extended / class_PngImage.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Image;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
8
9 // Import SPL stuff
10 use \SplFileInfo;
11
12 /**
13  * A PNG image generator
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
17  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18  * @license             GNU GPL 3.0 or any newer version
19  * @link                http://www.shipsimu.org
20  *
21  * This program is free software: you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation, either version 3 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program. If not, see <http://www.gnu.org/licenses/>.
33  */
34 class PngImage extends BaseImage {
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43         }
44
45         /**
46          * Creates an instance of this image class
47          *
48          * @param       $templateInstance       A template instance
49          * @return      $imageInstance          An instance of this image class
50          */
51         public static final function createPngImage(CompileableTemplate $templateInstance) {
52                 // Get a new instance
53                 $imageInstance = new PngImage();
54
55                 // Set template instance
56                 $imageInstance->setTemplateInstance($templateInstance);
57
58                 // Set image type
59                 $imageInstance->setImageType('png');
60
61                 // Return the instance
62                 return $imageInstance;
63         }
64
65         /**
66          * Finish this image by producing it
67          *
68          * @return      void
69          * @todo Rewrite this to SplFileInfo/Object
70          */
71         public function finishImage () {
72                 $this->partialStub('Unfinished method.');
73                 return;
74
75                 // Call parent method
76                 parent::finishImage();
77
78                 // Get a file name for our image
79                 $cacheFile = $this->getTemplateInstance()->getImageCacheFile();
80
81                 // Does it exist?
82                 if (FrameworkBootstrap::isReadableFile($cacheFile)) {
83                         // Remove it
84                         unlink($cacheFile->getPathname());
85                 } // END - if
86
87                 // Finish the image and send it to a cache file
88                 imagepng($this->getImageResource(), $cacheFile->getPathname(), 9, PNG_ALL_FILTERS);
89         }
90
91 }