@@ 107-124 (lines=18) @@ | ||
104 | * @throws InvalidArgumentException If the source argument is not a string. |
|
105 | * @return Image Chainable |
|
106 | */ |
|
107 | public function open($source = null) |
|
108 | { |
|
109 | if ($source !== null && !is_string($source)) { |
|
110 | throw new InvalidArgumentException( |
|
111 | 'Source must be a string (file path)' |
|
112 | ); |
|
113 | } |
|
114 | $source = ($source) ? $source : $this->source(); |
|
115 | $this->resetTmp(); |
|
116 | if (!file_exists($source)) { |
|
117 | throw new Exception( |
|
118 | sprintf('File "%s" does not exist', $source) |
|
119 | ); |
|
120 | } |
|
121 | $tmp = $this->tmp(); |
|
122 | copy($source, $tmp); |
|
123 | return $this; |
|
124 | } |
|
125 | ||
126 | /** |
|
127 | * Save an image to a target. |
|
@@ 135-150 (lines=16) @@ | ||
132 | * @throws InvalidArgumentException If the target argument is not a string. |
|
133 | * @return Image Chainable |
|
134 | */ |
|
135 | public function save($target = null) |
|
136 | { |
|
137 | if ($target !== null && !is_string($target)) { |
|
138 | throw new InvalidArgumentException( |
|
139 | 'Target must be a string (file path)' |
|
140 | ); |
|
141 | } |
|
142 | $target = ($target) ? $target : $this->target(); |
|
143 | if (!is_writable(dirname($target))) { |
|
144 | throw new Exception( |
|
145 | sprintf('Target "%s" is not writable', $target) |
|
146 | ); |
|
147 | } |
|
148 | copy($this->tmp(), $target); |
|
149 | return $this; |
|
150 | } |
|
151 | ||
152 | /** |
|
153 | * Get the image's width, in pixels |