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

Monday, October 10, 2022

[FIXED] How to save the rotation of an image on server?

 October 10, 2022     gd, php     No comments   

Issue

$filename = '01.jpg';
$degrees = 90;
// Content type
header('Content-type: image/jpeg');

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
$rotate = imagejpeg($rotate);

I am using this please explain how to update those image


Solution

Please use code like below

function RotateImg($filename = '',$angle = 0,$savename = false)
    {
       $original   =   imagecreatefromjpeg($filename);
       $rotated    =   imagerotate($original, $angle, 0);
       if($savename == false) {
                header('Content-Type: image/jpeg');
                imagejpeg($rotated);
            }
        else {
           imagejpeg($rotated,$savename);
        }
        imagedestroy($rotated);
    }

$filename   =   'http://images.all-free-download.com/images/graphiclarge/beautiful_nature_landscape_02_hd_picture_166206.jpg';

$saveto     =   $_SERVER['DOCUMENT_ROOT']."/images/test.jpg";

RotateImg($filename,90,$saveto);


Answered By - Jalpa
Answer Checked By - David Goodson (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