diff --git a/inc/media.php b/inc/media.php
index 916be2796e530baf4f97bdfde8beb554ed9bfbea..cfe08f90609783b2c832d0afcedd51c21993f9ec 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -1804,6 +1804,7 @@ function media_resize_image($file, $ext, $w, $h=0){
     if($info == false) return $file; // that's no image - it's a spaceship!
 
     if(!$h) $h = round(($w * $info[1]) / $info[0]);
+    if(!$w) $w = round(($h * $info[0]) / $info[1]);
 
     // we wont scale up to infinity
     if($w > 2000 || $h > 2000) return $file;
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 5967494bfd24b0179f8a8a30d19a80846212dec5..f33b3f2f8cb0dee972ad6475ee1e2b944646a85a 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -78,8 +78,8 @@ if (defined('SIMPLE_TEST')) {
     unset($evt);
 
     //handle image resizing/cropping
-    if((substr($MIME, 0, 5) == 'image') && $WIDTH) {
-        if($HEIGHT) {
+    if((substr($MIME, 0, 5) == 'image') && ($WIDTH || $HEIGHT)) {
+        if($HEIGHT && $WDITH) {
             $data['file'] = $FILE = media_crop_image($data['file'], $EXT, $WIDTH, $HEIGHT);
         } else {
             $data['file'] = $FILE = media_resize_image($data['file'], $EXT, $WIDTH, $HEIGHT);