3 October 2013

This snippet shows you an example of using image_scale_and_crop function to scale and crop image as in image styles.

Source code viewer
  1. // Load image file entity.
  2. $file = file_load($fid);
  3. // Load image by uri.
  4. $image = image_load($file->uri);
  5. // Use Drupal's scale and crop function to do the work for you.
  6. image_scale_and_crop($image, $scale['width'], $scale['height']);
  7. // Save image to file, you don't need to save the file entity.
  8. image_save($image);
Programming Language: PHP