function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbottom, $ofsright, $ofsleft, $board, $setwidth, $setheight)
{
    global $CFG;
    $dir = $CFG->dirroot . '/mod/game/snakes/1';
    $im = imagecreatefromstring($imageasstring);
    //check if need resize
    if ($setwidth > 0 or $setheight > 0) {
        $source = $im;
        $width = imagesx($source);
        $height = imagesy($source);
        $factorx = $setwidth / $width;
        $factory = $setheight / $height;
        $factor = $factorx < $factory || $factory == 0 ? $factorx : $factory;
        $newwidth = $width * $factor;
        $newheight = $height * $factor;
        $im = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresized($im, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    }
    $cx = imagesx($im) - $ofsright - $ofsleft;
    $cy = imagesy($im) - $ofstop - $ofsbottom;
    $color = 0xff0000;
    for ($i = 0; $i <= $colsx; $i++) {
        imageline($im, $ofsleft + $i * $cx / $colsx, $ofstop, $ofsleft + $i * $cx / $colsx, $cy + $ofstop, $color);
    }
    for ($i = 0; $i <= $colsy; $i++) {
        imageline($im, $ofsleft, $ofstop + $i * $cy / $colsy, $cx + $ofsleft, $ofstop + $i * $cy / $colsy, $color);
    }
    $filenamenumbers = $dir . '/numbers.png';
    $img_numbers = imageCreateFrompng($filenamenumbers);
    $size_numbers = getimagesize($filenamenumbers);
    for ($iy = 0; $iy < $colsy; $iy++) {
        if ($iy % 2 == 0) {
            $inc = false;
            $num = ($colsy - $iy) * $colsy;
        } else {
            $inc = true;
            $num = ($colsy - $iy) * $colsy - ($colsy - 1);
        }
        $ypos = $iy * $cy / $colsy + $ofstop;
        for ($ix = 0; $ix < $colsx; $ix++) {
            $xpos = $ix * $cx / $colsx + $ofsleft;
            shownumber($im, $img_numbers, $num, $xpos, $ypos, $cx / 4, $cy / 4, $size_numbers);
            $num = $inc ? $num + 1 : $num - 1;
        }
    }
    makeboard($im, $dir, $cx, $cy, $board, $colsx, $colsy, $ofsleft, $ofstop);
    return $im;
}
 function fn_makeImage($photographName, $selectionToPhotographRectangle = null, $zoom = 1, $width = null, $height = null, $filepath = null)
 {
     $imageSpecs = getimagesize($photographName);
     $extension = substr($photographName, -4);
     switch (strtolower($extension)) {
         case '.jpg':
             $image = imageCreateFromJpeg($photographName);
             break;
         case '.png':
             $image = imageCreateFrompng($photographName);
             break;
         case '.gif':
             $image = imageCreateFromGif($photographName);
             break;
         default:
             $image = imageCreateFromJpeg($photographName);
             break;
     }
     // try to split bounding box on comma ','
     $coordiantesArray = split(",", $selectionToPhotographRectangle);
     if (!$coordiantesArray[1]) {
         // try to split on space ' '
         $coordiantesArray = split(" ", $selectionToPhotographRectangle);
     }
     if (!$coordiantesArray[1]) {
         // still no split? use whole image
         $coordiantesArray = array(0, 0, $imageSpecs[0], $imageSpecs[1]);
     }
     // translate boundingbox's x1,y1,x2,y2 to x1,y1,w,h
     $fn_x1 = $coordiantesArray[0];
     $fn_y1 = $coordiantesArray[1];
     $fn_w = $coordiantesArray[2] - $coordiantesArray[0];
     $fn_h = $coordiantesArray[3] - $coordiantesArray[1];
     if (!$zoom) {
         // no zoom? give full size
         $zoom = 1;
     }
     displayDebug("selection: {$selectionToPhotographRectangle}", 3);
     displayDebug("\n{$fn_x1} | {$fn_y1} | {$fn_w} | {$fn_h} ", 3);
     // adjust for width and height params if passed
     if ($width && !$height) {
         $height = $width * $imageSpecs[1] / $imageSpecs[0];
     } else {
         if (!$width) {
             $width = $fn_w * $zoom;
         }
         if (!$height) {
             $height = $fn_h * $zoom;
         }
     }
     // let's grabbed the region
     #$croppedImage=ImageCreate($width, $height);
     $croppedImage = imagecreatetruecolor($width, $height);
     imagecopyresized($croppedImage, $image, 0, 0, $coordiantesArray[0], $coordiantesArray[1], $width, $height, $fn_w, $fn_h);
     $image = $croppedImage;
     if ($filepath) {
         // output to file
         switch (strtolower($extension)) {
             // send to browser with proper header
             case '.jpg':
                 imagejpeg($image, $filepath);
                 break;
             case '.png':
                 imagepng($image, $filepath);
                 break;
             case '.gif':
                 imageGif($image, $filepath);
                 break;
             default:
                 imagejpeg($image, $filepath);
                 break;
         }
     } else {
         // output to browser
         switch (strtolower($extension)) {
             // send to browser with proper header
             case '.jpg':
                 header('Content-Type: image/jpeg');
                 imagejpeg($image);
                 break;
             case '.png':
                 header('Content-Type: image/png');
                 imagepng($image);
                 break;
             case '.gif':
                 header('Content-Type: image/gif');
                 imageGif($image);
                 break;
             default:
                 header('Content-Type: image/jpeg');
                 imagejpeg($image);
                 break;
         }
     }
     // delete image from memory
     imagedestroy($image);
     return true;
 }
Example #3
0
public function updateImage1($picname,$path,$prix="s_",$maxwidth=104,$maxheight=104){
	//1. 定义获取基本信息
	$path = rtrim($path,"/"); //去除后面多余的"/"
	$info1 = getimagesize($path."/".$picname);  //获取图片文件的属性信息
	$width = $info1[0]; //原图片的宽度
	$height = $info1[1]; //原图片的高度
	
	//2. 计算压缩后的尺寸
	if(($maxwidth/$width)<($maxheight/$height)){
		$w=$maxwidth;//新图片的宽度
		$h=($maxwidth/$width)*$height;//新图片的高度
	}else{
		$h=$maxheight;//新图片的宽度
		$w=($maxheight/$height)*$width;//新图片的高度
	}


	//3. 创建图像源
	$newim =imagecreateTrueColor($w,$h); //新图片源
	//根据原图片类型来创建图片源
	switch($info1[2]){
		case 1: //gif格式
			$srcim = imageCreateFromgif($path."/".$picname);
			break;
		case 2: //jpeg格式
			$srcim = imageCreateFromjpeg($path."/".$picname);
			break;
		case 3: //png格式
			$srcim = imageCreateFrompng($path."/".$picname);
			break;
		case 6: //bmp格式
			$srcim = imageCreateFrompng($path."/".$picname);
			break;
		default:
			exit("无效的图片格式!");
			break;
	}

	//4. 执行缩放处理
	imagecopyresampled($newim,$srcim,0,0,0,0,$w,$h,$width,$height);


	//5. 输出保存绘画
	//header("Content-Type:".$info['mime']); //设置响应类型为图片格式
	//根据原图片类型来保存新图片
	switch($info1[2]){
		case 1: //gif格式
			imagegif($newim,$path."/".$prix.$picname); //保存
			//imagegif($newim);//输出
			break;
		case 2: //jpeg格式
			imagejpeg($newim,$path."/".$prix.$picname);
			//imagejpeg($newim);
			break;
		case 3: //png格式
			imagepng($newim,$path."/".$prix.$picname);
			//imagepng($newim);
			break;
		case 6: //bmp格式
			imagebmp($newim,$path."/".$prix.$picname);
			break;
	}

	//6. 销毁资源
	imageDestroy($newim);
	imageDestroy($srcim);
}
Example #4
0
<?php

if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], "section=Fits|Zeugnis")) {
    $fullname = $_GET['forename'] . " " . $_GET['name'];
    header("Content-type: image/png");
    //$picture = imagecreatefrompng( "http://".$_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'],0,-strlen(basename($_SERVER['PHP_SELF'])))."../../../../smarty/templates/web/images/FITS.png");
    $curl = curl_init("http://" . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, -strlen(basename($_SERVER['PHP_SELF']))) . "../../../../smarty/templates/web/images/FITS.png");
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_VERBOSE, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($curl);
    file_put_contents("image.png", $output);
    $picture = imageCreateFrompng('image.png');
    $black = ImageColorAllocate($picture, 0, 0, 0);
    imagestring($picture, 5, 50, 30, $fullname, $black);
    imagestring($picture, 5, 120, 77, $_GET['year'], $black);
    ImagePng($picture);
    imageDestroy($picture);
    unlink("image.png");
} else {
    print "Kein Direktzugriff erlaubt!";
}
Example #5
0
<?php