PHPで画像を上下反転させ保存する
2024/01/12
やりたかった事は、下記の通り。
・既にフォルダに保存されている画像を上下反転させる
・上下反転させた画像を上書き保存する
■ソース
<?
error_reporting(E_ALL & ~E_NOTICE);
$img_fir             = './img/';
$file_name         = 'test.jpg';
$img_url         = $img_fir . $file_name;
if ($_GET['mode'] == 'image_return') {
$source             = imagecreatefromjpeg($img_url);
$degrees         = 180;
$rotate             = imagerotate($source,$degrees, 0);
imagejpeg($rotate,$img_url);
header("Location:./index.php");
}
?>
<html>
<head>
<script type="text/javascript">
function image_return () {
location.href = './index.php?mode=image_return';
}
</script>
</head>
<body>
<img src="<?=$img_url . '?stamp=' . time();?>" width="200px" height="150px"><br>
<input type="button" onClick="return image_return();" value="上下反転">
</body>
</html>
■関数
imagecreatefromjpeg(画像名)
http://php.net/manual/ja/function.imagecreatefromjpeg.php
新しい画像をファイルあるいは URL から作成する
imagerotate(画像名、回転角度、回転後に重ねられない部分の色)
http://php.net/manual/ja/function.imagerotate.php
指定された角度で画像を回転する
imagejpeg(保存したい画像、保存するパス)
http://php.net/manual/ja/function.imagejpeg.php
画像をブラウザあるいはファイルに出力する
関連記事
- 
					
													
											
				 - 
					
FLASHから受信した画像をPHPで保存し、サムネイルも作る
■参考サイト ・FLASH http://www.ilovex.co.jp/bl ...
 
- 
					
													
											
				 - 
					
formのinput="file"でディレクトリを選択させ、ディレクトリ内のファイルを全てアップロードする方法
フォームで複数のファイルをアップロードしたい場合、input="file"を複数 ...
 
- 
					
													
											
				 - 
					
CodeIgniter4でフォームからファイルをアップロードし保存する方法
CodeIgniter4.4.4でformから画像等のファイルをアップロードし、 ...
 
- 
					
													
											
				 - 
					
PHPでスマホ(iPhone / Android)に画像をダウンロードさせる方法とダウンロード後の保存場所について
PHPで作ったシステムにスマホ(iPhone / Android)でアクセスし何 ...
 
- 
					
													
											
				 - 
					
PHPからWebAPI(screendot)経由で他サイトのスクリーンショットを取得する方法
PHPで他サイトのスクリーンショットを取得したい。今回はライブラリは無しで実現し ...