summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-03-14 16:19:11 -0700
committerPatrick Davison <snapwilliam@gmail.com>2013-03-14 16:19:11 -0700
commiteaa3fb3f863b4cec711fec01f09b38a1ab333eef (patch)
treecce29865f8b33da7571de154eeb3a7028e940ef1
parentf4691c84a4942b60c4cfb8f2845e63a3adde358e (diff)
downloadpathery-eaa3fb3f863b4cec711fec01f09b38a1ab333eef.tar.xz
Image rotation for emblems.
-rw-r--r--images/marks/rotate.php64
-rw-r--r--images/rotate.php20
2 files changed, 64 insertions, 20 deletions
diff --git a/images/marks/rotate.php b/images/marks/rotate.php
new file mode 100644
index 0000000..9b0a3fe
--- /dev/null
+++ b/images/marks/rotate.php
@@ -0,0 +1,64 @@
+<?php
+// File and rotation
+$filename = 'OffsetStripesDiagonal_B.png';
+$rotate = $_GET['r'] * 1;
+//Probably not the best syntax.
+if (!is_int($rotate) OR !($rotate > 0) OR !($rotate < 4)) exit;
+
+$emblem = $_GET['emblem'];
+$degrees = $_GET['r'] * 90;
+
+// Content type
+header('Content-type: image/jpeg');
+//TODO Add cache
+
+$simage = @imagecreatefrompng($emblem);
+if(!$simage) {
+ exit;
+}
+
+$background = imagecolorallocate($simage, 0, 0, 0);
+//$simage = rotateMaintain($simage, $degrees, $background);
+$simage = imagerotate($simage, $degrees, 0);
+// removing the black from the placeholder
+imagecolortransparent($simage, $background);
+// turning off alpha blending (to ensure alpha channel information
+// is preserved, rather than removed (blending with the rest of the
+// image in the form of black))
+imagealphablending($simage, false);
+// turning on alpha channel information saving (to ensure the full range
+// of transparency is preserved)
+imagesavealpha($simage, true);
+imagepng($simage);
+
+
+
+//Couldn't do this and maintain transparency ?
+function rotateMaintain($img1, $angle, $background) {
+ $width_before = imagesx($img1);
+
+ $height_before = imagesy($img1);
+ $img1 = imagerotate($img1, $angle, $background);
+
+ //but imagerotate scales, so we clip to the original size
+ $img2 = @imagecreatetruecolor($width_before, $height_before);
+ $new_width = imagesx($img1); // whese dimensions are
+ $new_height = imagesy($img1);// the scaled ones (by imagerotate)
+ imagecopyresampled(
+ $img2, $img1,
+ 0, 0,
+ ($new_width-$width_before)/2,
+ ($new_height-$height_before)/2,
+ $width_before,
+ $height_before,
+ $width_before,
+ $height_before
+ );
+ return $img2;
+}
+
+
+
+
+
+?> \ No newline at end of file
diff --git a/images/rotate.php b/images/rotate.php
deleted file mode 100644
index ae0df87..0000000
--- a/images/rotate.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-// File and rotation
-$filename = 'OverlayStart50.png';
-
-$degrees = $_GET['r'] * 90;
-//$degrees = 180;
-
-// Content type
-header('Content-type: image/jpeg');
-
-// Load
-$source = imagecreatefrompng($filename);
-
-// Rotate
-$rotate = imagerotate($source, $degrees, 0);
-
-// Output
-imagepng($rotate);
-
-?> \ No newline at end of file