'HandleRotatePicture')); SDVA($HandleAuth, array('rotatepic'=>'upload')); SDVA($RotatePicture, array( 'ImTypes' => array(1=>"gif",2=>"jpeg",3=>"png",15=>"wbmp",16=>"xbm",18=>"webp"), 'ImRx' => "/\\.(gif|png|jpe|jpe?g|wbmp|xbm|webp)$/i", 'SkipRx' => "/^th\\d+---/i", // thumbnails 'ImgFmt' => "", 'ListFmt' => '* %%list filterable%% %3$s\\\\'."\n" . ' \'\'\'%1$s\'\'\': rotate [[{$FullName}?action=rotatepic&upname=%2$s&do=left|left]] ' . ' [[{$FullName}?action=rotatepic&upname=%2$s&do=right|right]] ' . ' [[{$FullName}?action=rotatepic&upname=%2$s&do=udown|upside down]]; ' . 'flip [[{$FullName}?action=rotatepic&upname=%2$s&do=fliph|horizontal]] ' . ' [[{$FullName}?action=rotatepic&upname=%2$s&do=flipv|vertical]] ' ."\n" , )); Markup('(:rotatelist:)', 'directives', '/\\(:rotatelist:\\)/', 'FmtRotateList'); function FmtRotateList($m) { global $UploadFileFmt, $RotatePicture, $MarkupToHTML; extract($MarkupToHTML); $uploaddir = FmtPageName($UploadFileFmt, $pagename); $dirp = @opendir($uploaddir); if (!$dirp) return ''; $flist = array(); while (($fname=readdir($dirp)) !== false) { if ($fname[0] == '.') continue; if (! preg_match($RotatePicture['ImRx'], $fname)) continue; if (preg_match($RotatePicture['SkipRx'], $fname)) continue; $flist[$fname] = filemtime("$uploaddir/$fname"); } closedir($dirp); ksort($flist, SORT_FLAG_CASE | SORT_NATURAL); $out = ""; $fmt = $RotatePicture['ListFmt']; $x = strpos($fmt, '%3$s') === false? false:true; foreach($flist as $fname=>$mtime) { if($x) { $a = [ '$fname' => PHSC($fname, ENT_QUOTES), '$url' => DownloadUrl($pagename, $fname), '$mtime' => $mtime, ]; $html = strtr($RotatePicture['ImgFmt'], $a); $img = Keep($html); } else $img = ''; $ename = rawurlencode($fname); $out .= sprintf($RotatePicture['ListFmt'], $fname, $ename, $img); } return PRR($out); } function HandleRotatePicture($pagename, $auth = 'upload') { global $UploadFileFmt, $Now, $RotatePicture; $choices = [ 'left'=> 90, 'right'=> -90, 'udown'=> 180, 'flipb'=> 180, ]; $choices2 = [ 'fliph'=> IMG_FLIP_HORIZONTAL, 'flipv'=> IMG_FLIP_VERTICAL, ]; $upname = stripmagic(@$_REQUEST['upname']); if(!$upname) Abort("? Nothing to do (upname)."); $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); if(!$page) Abort("?No permissions to $auth @ $pagename"); $upname = MakeUploadName($pagename, $upname); $fpath = FmtPageName("$UploadFileFmt/$upname", $pagename); if(!file_exists($fpath)){Abort("? file '$fpath' not found."); exit;} $do = $_REQUEST['do']??''; if($do && isset($choices[$do])) { $dofn = 'imagerotate'; $doarg = [$choices[$do], 0]; } elseif($do && isset($choices2[$do])) { $dofn = 'imageflip'; $doarg = [$choices2[$do]]; } else { $deg = floatval(@$_REQUEST['deg']); if(!$deg) Abort("? Nothing to do (deg)."); $dofn = 'imagerotate'; $doarg = [$deg, 0]; } list($W, $H, $T) = @getimagesize($fpath); if(!isset($RotatePicture['ImTypes'][$T])){Abort("? format $T not supported."); exit;} $fcreate = "imagecreatefrom".$RotatePicture['ImTypes'][$T]; if (!function_exists($fcreate)){Abort("? No such function $fcreate.");} $fsave = "image".$RotatePicture['ImTypes'][$T]; if (!function_exists($fsave)){Abort("? No such function $fsave.");} $img = $fcreate($fpath); if (!@$img){Abort("? Could not load picture from $fpath.");} $rotated = $dofn($img, ...$doarg); if(!$rotated) { Abort("? could not rotate $fpath."); } if($rotated === true) $rotated = $img; # flip rename($fpath, "$fpath,$Now"); $fsave($rotated, $fpath); touch($fpath); clearstatcache(); HandleDispatch($pagename, 'download'); }