Overview

Namespaces

  • MOC
    • Adapter
    • Core
      • Changelog
      • Depending
      • Drive
        • Directory
        • File
      • Error
        • Register
        • Type
      • Journal
      • Proxy
      • Template
      • Xml
    • Extension
      • Excel
      • Flot
      • Mail
      • Pdf
      • Word
      • Xml
      • YUICompressor
      • Zip
    • Generic
      • Common
      • Device
        • Extension
        • Widget
    • Module
      • Database
        • Driver
      • Drive
      • Image
        • Font
      • Installer
      • Network
        • Ftp
          • Directory
          • File
          • Transport
        • Http
        • ParcelTracker
          • Carrier
      • Office
        • Chart
          • Axis
        • Document
          • Excel
            • Cell
              • Format
              • Style
                • Border
                  • Bottom
                  • Left
                  • Right
                  • Top
                • Font
            • Close
            • Page
            • Worksheet
          • Pdf
            • Close
            • Font
            • Page
              • Margin
              • Position
            • Text
          • Xml
            • Close
        • Image
        • Mail
          • Address
          • Content
      • Packer
        • Yui
        • Zip
      • Template
    • Plugin
      • Gateway
      • Repository
      • Shared
  • PHP

Classes

  • Close
  • Filter
  • Font
  • Open
  • Resize
  • Resource
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * LICENSE (BSD)
  4:  *
  5:  * Copyright (c) 2012, Gerd Christian Kunze
  6:  * All rights reserved.
  7:  *
  8:  * Redistribution and use in source and binary forms, with or without
  9:  * modification, are permitted provided that the following conditions are
 10:  * met:
 11:  *
 12:  *  * Redistributions of source code must retain the above copyright
 13:  *    notice, this list of conditions and the following disclaimer.
 14:  *
 15:  *  * Redistributions in binary form must reproduce the above copyright
 16:  *    notice, this list of conditions and the following disclaimer in the
 17:  *    documentation and/or other materials provided with the distribution.
 18:  *
 19:  *  * Neither the name of Gerd Christian Kunze nor the names of the
 20:  *    contributors may be used to endorse or promote products derived from
 21:  *    this software without specific prior written permission.
 22:  *
 23:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 24:  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 25:  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 26:  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 27:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 28:  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 29:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 30:  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 31:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 32:  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 33:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 34:  *
 35:  * Resize
 36:  * 13.09.2012 22:33
 37:  */
 38: namespace MOC\Module\Office\Image;
 39: use MOC\Api;
 40: use MOC\Generic\Device\Module;
 41: use MOC\Module\Office\Image\Resource;
 42: 
 43: /**
 44:  *
 45:  */
 46: class Resize implements Module {
 47:     /**
 48:      * Get Changelog
 49:      *
 50:      * @static
 51:      * @return \MOC\Core\Changelog
 52:      */
 53:     public static function InterfaceChangelog() {
 54:         return Api::Core()->Changelog();
 55:     }
 56: 
 57:     /**
 58:      * Get Dependencies
 59:      *
 60:      * @static
 61:      * @return \MOC\Core\Depending
 62:      */
 63:     public static function InterfaceDepending() {
 64:         return Api::Core()->Depending();
 65:     }
 66: 
 67:     /**
 68:      * Get Singleton/Instance
 69:      *
 70:      * @static
 71:      * @return Resize
 72:      */
 73:     public static function InterfaceInstance() {
 74:         return new Resize();
 75:     }
 76: 
 77:     /** @var Resource $Resource */
 78:     private $Resource = null;
 79: 
 80:     /**
 81:      * @param Resource $Resource
 82:      *
 83:      * @return $this
 84:      */
 85:     public function UseResource( Resource $Resource ) {
 86:         $this->Resource = $Resource;
 87:         return $this;
 88:     }
 89: 
 90:     /**
 91:      * @param null $Width
 92:      * @param null $Height
 93:      *
 94:      * @return Resize
 95:      */
 96:     public function PixelRelative( $Width = null, $Height = null ) {
 97:         $ResourceWidth = $this->GetWidth();
 98:         $ResourceHeight = $this->GetHeight();
 99:         if( ( $Width !== null ) || ( $Height !== null ) ) {
100:             $Width = ( $Width === null ? ( ( 100 / $ResourceHeight * $Height ) / 100 * $ResourceWidth ) : $Width );
101:             $Height = ( $Height === null ? ( ( 100 / $ResourceWidth * $Width ) / 100 * $ResourceHeight ) : $Height );
102:         }
103:         $Ratio = $ResourceWidth / $ResourceHeight;
104:         if( ( $Height * $Ratio ) > $Width ) {
105:             $Height = $Width / $Ratio;
106:         } else {
107:             $Width = $Height * $Ratio;
108:         }
109:         return $this->PercentAbsolute( round( $Width ), round( $Height ) );
110:     }
111: 
112:     /**
113:      * @param null $Width
114:      * @param null $Height
115:      *
116:      * @return Resize
117:      */public function PixelAbsolute( $Width = null, $Height = null ) {
118:         $ResourceWidth = $this->GetWidth();
119:         $ResourceHeight = $this->GetHeight();
120:         if( ! ( $Width !== null ) && ( $Height !== null ) ) {
121:             $Width = ( $Width === null ? $ResourceWidth : $Width );
122:             $Height = ( $Height === null ? $ResourceHeight : $Height );
123:         }
124:         $Resource = Resource::InterfaceInstance()->Create( $Width, $Height );
125:         imagecopyresampled( $Resource->Get(), $this->Resource->Get(), 0, 0, 0, 0, $Width, $Height, $ResourceWidth, $ResourceHeight );
126:         return $this;
127:     }
128: 
129:     /**
130:      * @param null $Width
131:      * @param null $Height
132:      *
133:      * @return Resize
134:      */public function PercentRelative( $Width = null, $Height = null ) {
135:         $Width = ( $Width === null ? 1 : $Width );
136:         $Height = ( $Height === null ? 1 : $Height );
137:         return $this->PixelRelative( $this->GetWidth() * $Width, $this->GetHeight() * $Height );
138:     }
139: 
140:     /**
141:      * @param null $Width
142:      * @param null $Height
143:      *
144:      * @return Resize
145:      */public function PercentAbsolute( $Width = null, $Height = null ) {
146:         $Width = ( $Width === null ? 1 : $Width );
147:         $Height = ( $Height === null ? 1 : $Height );
148:         return $this->PixelAbsolute( $this->GetWidth() * $Width, $this->GetHeight() * $Height );
149:     }
150: 
151:     /**
152:      * @return int
153:      */
154:     public function GetWidth() {
155:         return imagesx( $this->Resource->Get() );
156:     }
157: 
158:     /**
159:      * @return int
160:      */
161:     public function GetHeight() {
162:         return imagesy( $this->Resource->Get() );
163:     }
164: }
165: 
API documentation generated by ApiGen 2.8.0