1
0
minetest-skindb-oldwebdb/functions.php

64 lines
2.5 KiB
PHP

<?php
/** turn flip the image template for the rear of the skin */
function ImageCopyFliped($dst_im,$src_im,$dst_x,$dst_y,$src_x,$src_y,$src_w,$src_h )
{
$img_temp = imagecreatetruecolor($src_w, $src_h);
imagesavealpha($img_temp,true);
$white = imagecolorallocatealpha($img_temp, 255, 255, 255, 127);
imagefill($img_temp, 0, 0, $white);
imageCopy($img_temp, $src_im, 0, 0, $src_x, $src_y, $src_w,$src_h);
imageflip($img_temp,IMG_FLIP_HORIZONTAL);
imageCopy($dst_im, $img_temp, $dst_x, $dst_y, 0, 0, $src_w,$src_h);
imagedestroy($img_temp) ;
}
/** creat the front view of the skin, using the image resource, inside we call for the rear also */
function create2d($img_src,$scale)
{
imagesavealpha($img_src,true);
$width = 16;
$height = 32;
$img_out = imagecreatetruecolor($width, $height);
$white = imagecolorallocatealpha($img_out, 255, 255, 255, 127);
imagefill($img_out, 0, 0, $white);
imagesavealpha($img_out,true);
imageCopy($img_out, $img_src, 4, 0, 8, 8, 8, 8);
imageCopy($img_out, $img_src, 0, 8, 44, 20, 4, 12);
imageCopyFliped($img_out, $img_src, 12, 8, 44, 20, 4, 12);
imageCopy($img_out, $img_src, 4, 8, 20, 20, 8, 12);
imageCopy($img_out, $img_src, 8, 20, 4, 20, 4, 12);
imageCopyFliped($img_out, $img_src, 4, 20, 4, 20, 4, 12);
//imageantialias($img_out, false); // not works cos only usefully in 32bit images without alpha
$width = 16;
$height = 32;
$newwidth = $width * $scale;
$newheight = $height * $scale;
$out = imagecreatetruecolor($newwidth, $newheight);
$white = imagecolorallocatealpha($out, 255, 255, 255, 127);
imagefill($out, 0, 0, $white);
//imagesavealpha($img_out,true);
//imagesavealpha($thumb,true);
imagecopyresized($out, $img_out, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagesavealpha($out,true);
return $out;
}
/** generate the 2d plain view file on filesystem from database */
function save_images($img_src,$id)
{
$size = 1;
$thumb = create2d($img_src,$size);
@mkdir("./skins");
@mkdir("./skins/".$size."");
imagepng($thumb,"./skins/".$size."/".$id.".png");
$size = 5;
$thumb = create2d($img_src,$size);
@mkdir("./skins");
@mkdir("./skins/".$size."");
imagepng($thumb,"./skins/".$size."/".$id.".png");
return true;
}
?>