Skip to content

Instantly share code, notes, and snippets.

@kijtra
Created May 25, 2011 05:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kijtra/990417 to your computer and use it in GitHub Desktop.
Save kijtra/990417 to your computer and use it in GitHub Desktop.
[PHP] GDを使った画像の反転(縦・横)
<?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