diff --git a/flickr.admin.inc b/flickr.admin.inc
index 380c9a1..080d6c4 100644
--- a/flickr.admin.inc
+++ b/flickr.admin.inc
@@ -113,6 +113,15 @@ function flickr_admin_settings() {
     '#default_value' => variable_get('flickr_css', 1),
     '#description' => t("Uncheck to take care of the styling yourself in custom CSS.<br />Side note: Extend CSS even further with the !style_doc. If you use Flickr Filter, you might find the <a href='https://drupal.org/project/autofloat'>AutoFloat module</a> useful.", array('!style_doc' => $style_doc)),
   );
+  // Offer the following setting if both allow_url_fopen and curl are enabled.
+  if (ini_get("allow_url_fopen") && function_exists('curl_version')) {
+    $form['flickr_curl'] = array(
+      '#type' => 'checkbox',
+      '#title' => t("Use cURL to determine the image width instead of the PHP function 'getimagesize'."),
+      '#default_value' => variable_get('flickr_curl', 0),
+      '#description' => t("It might be faster. <a href='https://stackoverflow.com/a/4635991'>More info</a>."),
+    );
+  }
   $form['info_settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Flickr info to use'),
diff --git a/flickr.install b/flickr.install
index 54ecfa8..0642450 100644
--- a/flickr.install
+++ b/flickr.install
@@ -13,6 +13,7 @@ function flickr_uninstall() {
   variable_del('flickr_cache_duration');
   variable_del('flickr_class');
   variable_del('flickr_css');
+  variable_del('flickr_curl');
   variable_del('flickr_default_size_album');
   variable_del('flickr_default_userid');
   variable_del('flickr_opening_size');
diff --git a/flickr.module b/flickr.module
index 6f66738..2c3d313 100644
--- a/flickr.module
+++ b/flickr.module
@@ -361,7 +361,60 @@ function theme_flickr_photo($variables) {
   // If it is not a square.
   if (!isset($width)) {
     // Get the real width of the image.
-    list($width) = getimagesize($img_url);
+    // Reset the variable to use cURL if not available. In case it has been
+    // removed. Unlikely but possible.
+    if (!function_exists('curl_version')) {
+      variable_set('flickr_curl', 0);
+    }
+    // 'getimagesize' needs 'allow_url_fopen' to be enabled.
+    if (ini_get("allow_url_fopen") && variable_get('flickr_curl', 0) == 0) {
+      list($width) = getimagesize($img_url);
+    }
+    // Fallback to cURL if fopen cannot be used or cURL is set to be used.
+    elseif (function_exists('curl_version')) {
+      $width = ranger($img_url);
+    }
+    // Our server settings don't allow us to determine the image width.
+    // Use the known longest side of the image for the width. Leads to
+    // horizontal white space on portrait orientated images.
+    else {
+      switch ($size) {
+      case 't':
+        $width = '100';
+        break;
+
+      case 'm':
+        $width = '240';
+        break;
+
+      case 'n':
+        $width = '320';
+        break;
+
+      case 'z':
+        $width = '640';
+        break;
+
+      case 'c':
+        $width = '800';
+        break;
+
+      case 'b':
+        $width = '1024';
+        break;
+
+      case 'h':
+        $width = '1600';
+        break;
+
+      case 'k':
+        $width = '2048';
+        break;
+
+      default:
+        $width = '500';
+      }
+    }
   }
   $photo_url = flickr_photo_page_url($photo['owner'], $photo['id']);
   $info = flickr_photo_get_info($photo['id']);
@@ -736,3 +789,19 @@ function theme_flickr_flickrcomslideshow_simple($variables) {
   }
   return '<div class="flickr-slideshow"><object type="text/html" data="' . $src . '"></object></div>';
 }
+
+/**
+ * Alternative to the PHP function getimagesize. See
+ * http://stackoverflow.com/questions/4635936/super-fast-getimagesize-in-php.
+ */
+function ranger($url) {
+  $headers = array("Range: bytes=0-32768");
+  $curl = curl_init($url);
+  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+  $data = curl_exec($curl);
+  curl_close($curl);
+  $im = imagecreatefromstring($data);
+  $width = imagesx($im);
+  return $width;
+}
