File: imagecopyresampled_basic.phpt

package info (click to toggle)
php5 5.2.6.dfsg.1-1%2Blenny16
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 81,956 kB
  • ctags: 45,717
  • sloc: ansic: 545,818; sh: 18,463; php: 12,555; xml: 4,362; yacc: 2,430; lex: 2,294; makefile: 1,193; tcl: 1,128; awk: 693; cpp: 682; perl: 71; pascal: 24; sql: 22
file content (71 lines) | stat: -rw-r--r-- 2,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--TEST--
imagecopyresampled()
--SKIPIF--
<?php 
	if (!function_exists('imagecopyresampled')) die('skip imagecopyresampled() not available'); 
	require_once('skipif_imagetype.inc');
?>
--FILE--
<?php

/* Prototype  : bool imagecopyresampled  ( resource $dst_image  , resource $src_image  , int $dst_x  , int $dst_y  , int $src_x  , int $src_y  , int $dst_w  , int $dst_h  , int $src_w  , int $src_h  )
 * Description: Copy and resize part of an image with resampling.
 * Source code: ext/standard/image.c
 * Alias to functions: 
 */

echo "Simple test of imagecopyresampled() function\n";

$dest_lge = dirname(realpath(__FILE__)) . '/imagelarge.png';
$dest_sml = dirname(realpath(__FILE__)) . '/imagesmall.png';

// create a blank image
$image_lge = imagecreatetruecolor(400, 300);

// set the background color to black 
$bg = imagecolorallocate($image_lge, 0, 0, 0);

// fill polygon with blue
$col_ellipse = imagecolorallocate($image_lge, 0, 255, 0);

// draw the eclipse
imagefilledellipse($image_lge, 200, 150, 300, 200, $col_ellipse);

// output the picture to a file
imagepng($image_lge, $dest_lge);

// Get new dimensions
$percent = 0.5; // new image 50% of orginal
list($width, $height) = getimagesize($dest_lge);
echo "Size of orginal: width=". $width . " height=" . $height . "\n";

$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_sml = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_sml, $image_lge, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagepng($image_sml, $dest_sml);

list($width, $height) = getimagesize($dest_sml);
echo "Size of copy: width=". $width . " height=" . $height . "\n";

imagedestroy($image_lge); 
imagedestroy($image_sml);
 

echo "Done\n"; 
?>
--CLEAN--
<?php 
	$dest_lge = dirname(realpath(__FILE__)) . '/imagelarge.png';
	$dest_sml = dirname(realpath(__FILE__)) . '/imagesmall.png';
	@unlink($dest_lge);
	@unlink($dest_sml);
?>
--EXPECT--
Simple test of imagecopyresampled() function
Size of orginal: width=400 height=300
Size of copy: width=200 height=150
Done