php - How to crop image using GD image functions -


Everything in my code is doing a great job to create a thumbnail image of the uploaded photo.

Now all

  $ ext = end (blast)  

('.', $ _FILES ['profile_photo '] ['Name'])); ($ Ext == 'jpg' || $ ext == 'jpeg' || $ ext == 'png' || $ ext == 'gif') {$ tmp = $ _FILES ['profile_photo'] [' Tmp_name ']; If ($ ext == 'jpg' || $ ext == 'jpeg') $ src = imagecreatefromjpeg ($ tmp); And if ($ ext == 'png') $ src = imagecreatefrompng ($ tmp); Else $ src = imagecreatefromgif ($ tmp); List ($ width, $ height) = Matching ($ TMP); $ Thumb_width = 50; $ Thumb_height = ($ height / $ width) * $ thumb_width; $ Thumb_tmp = imagecreatetruecolor ($ thumb_width, $ thumb_height); $ Full_method = 200; $ Full_heat = ($ height / $ width) * $ full_method; $ Full_tmp = imagectatro color ($ full_method, $ full_highthought); Imagecopyresampled ($ thumb_tmp, $ src, 0, 0, 0, 0, $ thumb_width, $ thumb_height, $ width, $ height); Imagecopyresampled ($ full_tmp, $ src, 0, 0, 0, 0, $ full_method, $ full_highth, $ width, $ height); Imagejpeg ($ thumb_tmp, 'image / profile /'. $ User ['id'].'_ '. Time ().'_ thumbs'. $ Ext, 100); Imagejpeg ($ full_tmp, 'images / profile' '. $ User [' id '].'_'. Time ().'_complete '. $ Ext, 100); Imagedestroy ($ src); Imagedestroy ($ thumb_tmp); Imagedestroy ($ full_tmp); // Delete the old image from the server if none of this.}}

Any help would be greatly appreciated! I know that there is something to do with the pictures, but I can not figure out the mathematics for the crop from the center of the image. If I want to be my own celebrity, then please advise me not to use classes of other people.

After

right after $ full_tmp = imagecreatetruecolor ($ full_width, $ full_height); , add ...

  if ($ thumb_width> $ thumb_height) {$ thumb_offset = array ('x' = & gt; ($ thumb_width / 2 - 25) , 'Y' = & gt; 0); } Else {$ thumb_offset = array ('x' => 0, 'y' => ($ thumb_height / 2 - 25)); } $ Square_tmp = imagecreatetruecolor ($ thumb_width, $ thumb_height); Imagecopyresampled ($ square_tmp, $ src, 0, 0, $ thumb_offset ['x'], $ thumb_offset ['y'], 50, 50, $ width, $ height);   

Then save and destroy temp like the other two images.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -