image_scale

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 image_scale($source, $destination, $width, $height)
drupal7 image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = FALSE)

Scales an image to the given width and height while maintaining aspect ratio.

The resulting image can be smaller for one or both target dimensions.

see image_load()

Übergabeparameter

$image An image object returned by image_load().

$width The target width, in pixels. This value is omitted then the scaling will based only on the height value.

$height The target height, in pixels. This value is omitted then the scaling will based only on the width value.

$upscale Boolean indicating that files smaller than the dimensions will be scalled up. This generally results in a low quality image.

Rückgabewert

TRUE or FALSE, based on success.

See also

image_scale_and_crop()

Verwandte Themen

▾ 2 functions call image_scale()

file_validate_image_resolution in includes/file.inc
If the file is an image verify that its dimensions are within the specified maximum and minimum dimensions.
ImageToolkitTestCase::testScale in modules/simpletest/tests/image.test
Test the image_scale() function.

Code

includes/image.inc, line 194

<?php
function image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = FALSE) {
  $aspect = $image->info['height'] / $image->info['width'];

  if ($upscale) {
    // Set width/height according to aspect ratio if either is empty.
    $width = !empty($width) ? $width : $height / $aspect;
    $height = !empty($height) ? $height : $width / $aspect;
  }
  else {
    // Set impossibly large values if the width and height aren't set.
    $width = !empty($width) ? $width : 9999999;
    $height = !empty($height) ? $height : 9999999;

    // Don't scale up.
    if (round($width) >= $image->info['width'] && round($height) >= $image->info['height']) {
      return TRUE;
    }
  }

  if ($aspect < $height / $width) {
    $height = $width * $aspect;
  }
  else {
    $width = $height / $aspect;
  }

  return image_resize($image, $width, $height);
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen