Scale and crop image programmatically in Drupal 7

Public

Took this cool snippet from here: http://browse-tutorials.com/snippet/using-imagescaleandcrop-drupal-7

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

Comments

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?