Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload, resize, and crop center of image with PHP

I'm wanting to create a very very basic upload, resize, and crop PHP script. The functionality to this will be identical (last i checked anyway) to the method Twitter uses to upload avatar pictures.

I want the script to take any size image, resize the shortest side to 116px, then crop off the top and bottom (or left and right side if it's landscape) as to get a square 116px by 116px.

I don't want a bloated PHP script with client side resizing or anything, just a simple PHP resize and crop. How is this done?

like image 290
Adam Avatar asked Dec 27 '22 18:12

Adam


2 Answers

The GD Library is a good place to start.

http://www.php.net/manual/en/book.image.php

like image 194
jjwdesign Avatar answered Jan 05 '23 09:01

jjwdesign


There a simple to use, open source library called PHP Image Magician. It uses GD but simplifies it's usage to 3 lines.

Example of basis usage:

$magicianObj = new imageLib('racecar.jpg');
$magicianObj -> resizeImage(100, 200, 'crop');
$magicianObj -> saveImage('racecar_small.png');
like image 45
Jarrod Avatar answered Jan 05 '23 10:01

Jarrod