Skip to content

Commit c6c9a3e

Browse files
committed
Fixed GD cropsize bug
1 parent 8e6c972 commit c6c9a3e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

system/media/gd.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function resize($width, $height = 0, $method = 's') {
123123
}
124124

125125
public function stretch($width, $height = 0) {
126-
if (! $this->width || ! $this->height) {
126+
if (! $this->width || ! $this->height || ! $this->image) {
127127
return;
128128
}
129129

@@ -152,6 +152,10 @@ public function stretch($width, $height = 0) {
152152
}
153153

154154
public function crop($topX, $topY, $bottomX, $bottomY) {
155+
if (! $this->width || ! $this->height || ! $this->image) {
156+
return;
157+
}
158+
155159
$imageOld = $this->image;
156160
$this->image = imagecreatetruecolor($bottomX - $topX, $bottomY - $topY);
157161

@@ -163,7 +167,7 @@ public function crop($topX, $topY, $bottomX, $bottomY) {
163167
}
164168

165169
public function cropsize($width, $height = 0) {
166-
if (! $this->width || ! $this->height) {
170+
if (! $this->width || ! $this->height || ! $this->image) {
167171
return;
168172
}
169173

@@ -185,7 +189,14 @@ public function cropsize($width, $height = 0) {
185189
$crop_y = 0;
186190
}
187191

188-
$this->image = imagescale($this->image, $newWidth, $newHeight, IMG_BICUBIC_FIXED);
189-
$this->image = imagecrop($this->image, ['x' => 0, 'y' => 0, 'width' => $width, 'height' => $height]);
192+
$image = imagescale($this->image, $newWidth, $newHeight, IMG_BICUBIC_FIXED);
193+
194+
if ($image) {
195+
$image = imagecrop($image, ['x' => 0, 'y' => 0, 'width' => $width, 'height' => $height]);
196+
197+
if ($image) {
198+
$this->image = $image;
199+
}
200+
}
190201
}
191202
}

0 commit comments

Comments
 (0)