- && $box['height'] === $this->height
- && $box['x'] === 0
- && $box['y'] === 0
- && $box['w'] === $this->width
- && $box['h'] === $this->height
- && $this->type == $this->preferredType()) {
-
- @copy($this->filepath, $outpath);
- return $outpath;
+ && $box['height'] === $this->height
+ && $box['x'] === 0
+ && $box['y'] === 0
+ && $box['w'] === $this->width
+ && $box['h'] === $this->height
+ && $this->type == $this->preferredType()) {
+ if ($this->rotate == 0) {
+ // No rotational difference, just copy it as-is
+ @copy($this->filepath, $outpath);
+ return $outpath;
+ } elseif (abs($this->rotate) == 90) {
+ // Box is rotated 90 degrees in either direction,
+ // so we have to redefine x to y and vice versa.
+ $tmp = $box['width'];
+ $box['width'] = $box['height'];
+ $box['height'] = $tmp;
+ $tmp = $box['x'];
+ $box['x'] = $box['y'];
+ $box['y'] = $tmp;
+ $tmp = $box['w'];
+ $box['w'] = $box['h'];
+ $box['h'] = $tmp;
+ }