slice-image
Code (php)
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
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
<?php
// voorbeeld slice('test.jpg',9,60);
// maakt van test.jpg 9 images,met als quality=60, in een blok van 3x3 images
slice('test.jpg',9,60);
?>
<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="sliced/00.jpg" width="160" height="120" /></td>
<td><img src="sliced/10.jpg" width="160" height="120" /></td>
<td><img src="sliced/20.jpg" width="160" height="120" /></td>
</tr>
<tr>
<td><img src="sliced/01.jpg" width="160" height="120" /></td>
<td><img src="sliced/11.jpg" width="160" height="120" /></td>
<td><img src="sliced/21.jpg" width="160" height="120" /></td>
</tr>
<tr>
<td><img src="sliced/02.jpg" width="160" height="120" /></td>
<td><img src="sliced/12.jpg" width="160" height="120" /></td>
<td><img src="sliced/22.jpg" width="160" height="120" /></td>
</tr>
</table>
<?php
function cropimage($source,$x,$y,$w,$h,$piece,$quality){
list($width, $height) = getimagesize($source);
$image_p = imagecreatetruecolor($w, $h);
$image = imagecreatefromjpeg($source);
imagecopyresampled($image_p, $image, 0, 0, $x, $y, $w, $h, $w, $h);
return imagejpeg($image_p, $piece, $quality);
}
function slice($source,$parts,$quality){
if(!is_dir('sliced')) $dir = mkdir('sliced',0777);
list($imw,$imh) = getimagesize($source);
$newwidth = round($imw/sqrt($parts));
$newheight = round($imh/sqrt($parts));
for ($i=0;$i<sqrt($parts);$i++){
for ($j=0;$j<sqrt($parts);$j++){
$piece = 'sliced/'. $i.$j.'.jpg';
cropimage($source,$i*$newwidth,$j*$newheight,$newwidth,$newheight,$piece,$quality);
}
}
}
?>
// voorbeeld slice('test.jpg',9,60);
// maakt van test.jpg 9 images,met als quality=60, in een blok van 3x3 images
slice('test.jpg',9,60);
?>
<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="sliced/00.jpg" width="160" height="120" /></td>
<td><img src="sliced/10.jpg" width="160" height="120" /></td>
<td><img src="sliced/20.jpg" width="160" height="120" /></td>
</tr>
<tr>
<td><img src="sliced/01.jpg" width="160" height="120" /></td>
<td><img src="sliced/11.jpg" width="160" height="120" /></td>
<td><img src="sliced/21.jpg" width="160" height="120" /></td>
</tr>
<tr>
<td><img src="sliced/02.jpg" width="160" height="120" /></td>
<td><img src="sliced/12.jpg" width="160" height="120" /></td>
<td><img src="sliced/22.jpg" width="160" height="120" /></td>
</tr>
</table>
<?php
function cropimage($source,$x,$y,$w,$h,$piece,$quality){
list($width, $height) = getimagesize($source);
$image_p = imagecreatetruecolor($w, $h);
$image = imagecreatefromjpeg($source);
imagecopyresampled($image_p, $image, 0, 0, $x, $y, $w, $h, $w, $h);
return imagejpeg($image_p, $piece, $quality);
}
function slice($source,$parts,$quality){
if(!is_dir('sliced')) $dir = mkdir('sliced',0777);
list($imw,$imh) = getimagesize($source);
$newwidth = round($imw/sqrt($parts));
$newheight = round($imh/sqrt($parts));
for ($i=0;$i<sqrt($parts);$i++){
for ($j=0;$j<sqrt($parts);$j++){
$piece = 'sliced/'. $i.$j.'.jpg';
cropimage($source,$i*$newwidth,$j*$newheight,$newwidth,$newheight,$piece,$quality);
}
}
}
?>