Created
May 25, 2011 05:42
-
-
Save kijtra/990417 to your computer and use it in GitHub Desktop.
[PHP] GDを使った画像の反転(縦・横)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//縦反転 | |
function flip_vertical($imgsrc){ | |
$x=imagesx($imgsrc); | |
$y=imagesy($imgsrc); | |
$flip=imagecreatetruecolor($x,$y); | |
if(imagecopyresampled($flip,$imgsrc,0,0,0,$y-1,$x,$y,$x,0-$y)){ | |
return $flip; | |
}else{ | |
return $imgsrc; | |
} | |
} | |
//横反転 | |
function flip_horizontal($imgsrc){ | |
$x=imagesx($imgsrc); | |
$y=imagesy($imgsrc); | |
$flip=imagecreatetruecolor($x,$y); | |
if(imagecopyresampled($flip,$imgsrc,0,0,$x-1,0,$x,$y,0-$x,$y)){ | |
return $flip; | |
}else{ | |
return $imgsrc; | |
} | |
} | |
/* つかいかた */ | |
$img=imagecreatefromjpeg('sample.jpg'); | |
$flip=flip_horizontal($img); | |
header("Content-type: image/jpeg"); | |
imagejpeg($flip); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment