Scale and crop image programmatically in Drupal 7


Took this cool snippet from here:

Get raw version
  1. // Load image file entity.
  2. $file = file_load($fid);
  4. // Load image by uri.
  5. $image = image_load($file->uri);
  7. // Use Drupal's scale and crop function to do the work for you.
  8. image_scale_and_crop($image, $scale['width'], $scale['height']);
  10. // Save image to file, you don't need to save the file entity.
  11. image_save($image);


amine's picture

thanks for this code

Pradeep's picture

what is the exact css for this code?
ie. I used this feature and it works good. but I want to know the css. whatever i try i can't make image to align in center for making thumbnail view.

Anonymous's picture

how this code is used? in the template.php or a custom module? inside a hook like hook_file_insert or something else?