PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to rotate image completely. with out showing the black portion

 October 11, 2022     gd, image, php     No comments   

Issue

I have an image I have to rotate that image 25 degree. if I rotate it shows some black background. How can I avoid that. How can I rotate image completely with out showing the black portion by using PHP GD. I cant use js for rotation. because I have to merge the image with another one after rotation. any body have the scripts for this please help me.


Solution

The black area is unavoidable on rotation - PHP (and GD for that matter) isn't Photoshop's content-aware-fill and won't generate more picture for you during the rotation to cover up the black bits.

You've got two choices:

  1. do some math and figure out what size of rectangle you can slice out of the rotated image to eliminate the black borders (eg: the post-rotation image will be smaller than the original)

  2. blow up the original image prior to rotating, such that after rotating, you can slice out a rectangular chunk that matches the original non-rotated size. Again, calls for a bit of math.

Of course, this all depends on just how you're rotating the image. Rotating on a corner will lead to vastly different results than rotating on the center of the image.



Answered By - Marc B
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing