function rotatePngImage($angle, $imagePath) { $image = imagecreatefrompng($imagePath); $image = rotateImage($image, $angle); // Turn off alpha blending and set alpha flag imagealphablending($image, false); imagesavealpha($image, true); imagepng($image); }
function view_data($file, $fthumb = null) { if (!$fthumb) { $fthumb = 400; } // Check if this is a continual or sensor network station if (preg_match("/conti/i", "substr({$file},0,4)")) { $url = UPLOADPATH . "/trigger/continual/"; } else { $url = UPLOADPATH . "/trigger/"; } // Set file name $file_orig = $url . $file; //echo $file_orig; if (!file_exists($file_orig)) { echo "Waveform Not Found. Try again later."; return; } // Set base directory: $dir_base = BASEPATH . "/qcnwp/earthquakes/view"; $dir_sub = basename($file, ".zip"); $dir = $dir_base . '/' . $dir_sub; // If already viewed (and image already generated), then dont remake the image: $jpgfile = "{$dir}/waveform.jpg"; if (!file_exists($jpgfile)) { // CMC note - test the file, not just the dir // rotateImage($jpgfile,$fthumb); //} else { // If not already made, make image: if (!file_exists($dir)) { mkdir($dir); } $file_new = $dir . '/' . $file; copy($file_orig, $file_new); if (!file_exists($file_new)) { echo "File does not exist: {$file}...\n"; } else { system(SHELL_CMD . " " . BASEPATH . "/qcnwp/earthquakes/view/plot_data.sh {$dir} > {$dir}/temp.txt"); rotateImage($jpgfile, $fthumb); } $jpgfile = "{$dir}/waveform.jpg"; } echo "<html><head></head><body>\n"; echo "<img src=\"http://qcn.stanford.edu/earthquakes/view/" . $dir_sub . "/waveform.jpg\" width=\"" . $fthumb . "\">\n"; echo "</body></head>\n"; // Remove all old data so it doesn't build up over time clear_old_views($dir_base); }
switch ($_REQUEST['action']) { case 'upload': print_r(json_encode(uploadHtmlEditorImage($allowedFormats, $maxSize, $imagesPath, $imagesUrl, $createThumbnails, $imagesTumbsUrl, $imagesThumbsPath))); break; case 'crop': $imageSrc = isset($_REQUEST["image"]) ? $_REQUEST["image"] : ''; $width = isset($_REQUEST["width"]) ? intval($_REQUEST["width"]) : 0; $height = isset($_REQUEST["height"]) ? intval($_REQUEST["height"]) : 0; $offsetLeft = isset($_REQUEST["offsetLeft"]) ? intval($_REQUEST["offsetLeft"]) : 0; $offsetTop = isset($_REQUEST["offsetTop"]) ? intval($_REQUEST["offsetTop"]) : 0; $zoom = isset($_REQUEST["zoom"]) ? intval($_REQUEST["zoom"]) : 1; print_r(json_encode(cropImage($imagesPath, $imagesThumbsPath, $imagesUrl, $imagesTumbsUrl, $imageSrc, $width, $height, $offsetLeft, $offsetTop, $zoom, $allowedFormats))); break; case 'rotate': $imageSrc = isset($_REQUEST["image"]) ? $_REQUEST["image"] : ''; print_r(json_encode(rotateImage($imagesPath, $imagesThumbsPath, $imagesUrl, $imageSrc))); break; case 'resize': $width = isset($_REQUEST["width"]) ? intval($_REQUEST["width"]) : 0; $height = isset($_REQUEST["height"]) ? intval($_REQUEST["height"]) : 0; $imageSrc = isset($_REQUEST["image"]) ? $_REQUEST["image"] : ''; print_r(json_encode(resizeImage($imagesPath, $imagesThumbsPath, $imagesUrl, $imageSrc, $width, $height))); break; case 'imagesList': $limit = isset($_REQUEST["limit"]) ? intval($_REQUEST["limit"]) : 10; $start = isset($_REQUEST["start"]) ? intval($_REQUEST["start"]) : 0; $query = isset($_REQUEST["query"]) ? $_REQUEST["query"] : 0; print_r(json_encode(getImages($imagesPath, $imagesUrl, $imagesTumbsUrl, $imagesThumbsPath, $allowedFormats, $start, $limit, $query))); break; case 'delete': $image = isset($_REQUEST["image"]) ? stripslashes($_REQUEST["image"]) : "";
function image_update($id, $date, $title, $description, $rotate) { $cn = connect_db(); if ($title == "") { $title = "No Title"; } if ($description == "") { $description = "No Description"; } $sql = "SELECT * FROM `photo` WHERE id='" . $id . "'"; $link = mysql_query($sql, $cn) or die("Error : " . mysql_error()); $data = mysql_fetch_assoc($link); $path1 = get_full_domain_path() . str_replace(get_domain_path(), "", $data['original_url']); $path2 = get_full_domain_path() . str_replace(get_domain_path(), "", $data['medium_url']); $path3 = get_full_domain_path() . str_replace(get_domain_path(), "", $data['thumb_url']); if ($rotate == "CW") { rotateImage($path1, "CW"); rotateImage($path2, "CW"); rotateImage($path3, "CW"); } if ($rotate == "CCW") { rotateImage($path1, "CCW"); rotateImage($path2, "CCW"); rotateImage($path3, "CCW"); } $d1 = date("Y-m-d", strtotime($date)); $d1 .= date(" H:i:s", time()); $sql = "update `photo` set upload_time='" . $d1 . "', title='" . formattext(htmlspecialchars(magicquotes($title))) . "', description='" . formattext(magicquotes(htmlspecialchars($description))) . "' where id='" . $id . "'"; $link = mysql_query($sql, $cn) or die("Error : " . mysql_error()); disconnect_db($cn); }
*** ROTATE IMAGES *** *********************/ error_reporting(E_ALL); ini_set('display_errors', '1'); date_default_timezone_set('UTC'); require_once '../../vendor/autoload.php'; use Elboletaire\Watimage\Watimage; function rotateImage($image, $deg, $output_image) { $wm = new Watimage(); $wm->setImage(array('file' => "files/{$image}", 'quality' => 90)); // file to use and export quality $wm->rotate($deg); if (!$wm->generate("results/{$output_image}")) { // handle errors... print_r($wm->errors); } } rotateImage('image.jpg', 45, 'rotate_jpg_45.jpg'); rotateImage('image.jpg', 90, 'rotate_jpg_90.jpg'); rotateImage('image.jpg', 180, 'rotate_jpg_180.jpg'); rotateImage('image.jpg', 270, 'rotate_jpg_270.jpg'); ############################ ### Check transparencies ### ############################ // Rotate png 45 deg rotateImage('image.png', 45, 'rotate_png_45.png'); // Rotate gif 45 deg [currently failing] rotateImage('image.gif', 45, 'rotate_gif_45.gif'); rotateImage('image.gif', 90, 'rotate_gif_90.gif'); echo "All images have been rotated.\n";
// 保存 if ($imagName_type == 1) { $result = imagegif($rotate, $aimFileName); } elseif ($imagName_type == 2) { $result = imagejpeg($rotate, $aimFileName); } elseif ($imagName_type == 3) { $result = imagepng($rotate, $aimFileName); } //释放资源 imagedestroy($source); return array('status' => $result, 'msg' => $aimFileName); } $filename = './images/gallery4942565920ef31230_g.jpg'; $aimFileName = './images/gallery4942565920ef31230_g----1.jpg'; // $imagesInfo = getimagesize($filename); $res = rotateImage($filename, 90, $aimFileName); echo "<pre>"; print_r($res); /** * 翻转图片(沿Y轴水平翻转或沿X轴垂直翻转) * * @param $imagName string 原图地址 * @param $type string 沿Y轴水平翻转或沿X轴垂直翻转 * @param $aimFileName string 目标图地址(存在则新建一张目标图,否则旋转原图) * * return bool */ function trunImage($imagName, $type = 'x', $aimFileName = '') { // 图片信息 list($imagName_w, $imagName_h, $imagName_type) = getimagesize($imagName);
$exif = exif_read_data($file); list($w, $h, $t) = getimagesize($file); $ratio = $w / $h; if ($ratio > 1) { $nw = 400; $nh = 400 / $ratio; } else { $nw = 400 * $ratio; $nh = 400; } $dst = imagecreatetruecolor($nw, $nh); imagecopyresampled($dst, $src, 0, 0, 0, 0, $nw, $nh, $w, $h); imagedestroy($src); $rot = array(3 => 180, 6 => 90, 8 => 270); if ($rot[$exif['Orientation']]) { $dst = rotateImage($dst, $rot[$exif['Orientation']]); } imagejpeg($dst, $c, 85); imagedestroy($dst); chmod($c, 0644); } echo "<a class=\"tf\" href=\"{$file}\" style=\"background-image: url('{$c}')\"><span>{$file}</span></a>\n"; } } // included because GD's imagerotate is broken in php 5.2 function rotateImage($img, $rotation) { $width = imagesx($img); $height = imagesy($img); switch ($rotation) { case 90: