1
0

organize code for uploads and 2dview generation

This commit is contained in:
mckaygerhard 2024-05-03 18:06:12 -04:00
parent a070e79d06
commit 31dd95cd46
2 changed files with 61 additions and 95 deletions

View File

@ -1,98 +1,64 @@
<?php
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, //linker arm Spiegeln!!
0, 0, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
$src_x, $src_y, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
$src_w,$src_h); /* und ist 96 Pixel breit und 90 Pixel hoch */
imageflip($img_temp,IMG_FLIP_HORIZONTAL);
imageCopy($dst_im, $img_temp, //linker arm Spiegeln!!
$dst_x,$dst_y, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
0, 0, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
$src_w,$src_h); /* und ist 96 Pixel breit und 90 Pixel hoch */
imagedestroy($img_temp) ;
}
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, //kopf
4, 0, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
8, 8, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
8, 8); /* und ist 96 Pixel breit und 90 Pixel hoch */
/** 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) ;
}
imageCopy($img_out, $img_src, //rechter arm
0, 8, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
44, 20, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
4, 12); /* und ist 96 Pixel breit und 90 Pixel hoch */
/** 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;
}
imageCopyFliped($img_out, $img_src, //linker arm Spiegeln!!
12, 8, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
44, 20, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
4, 12); /* und ist 96 Pixel breit und 90 Pixel hoch */
imageCopy($img_out, $img_src, //bauch
4, 8, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
20, 20, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
8, 12); /* und ist 96 Pixel breit und 90 Pixel hoch */
imageCopy($img_out, $img_src, //rechtes bein
8, 20, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
4, 20, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
4, 12); /* und ist 96 Pixel breit und 90 Pixel hoch */
imageCopyFliped($img_out, $img_src, //linkes bein Spiegeln!!
4, 20, /* imagecopy() an die Stelle ( 202, 0) in $Wiese, */
4, 20, /* der zu kopierende Bereich beginnt in $Sonne bei ( 0, 0) */
4, 12); /* und ist 96 Pixel breit und 90 Pixel hoch */
//imageantialias($img_out, false);
$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;
}
function save_images($img_src,$id){
$size = 1;
$thumb = create2d($img_src,$size);
//header("Content-Type: image/png");
@mkdir("./skins");
@mkdir("./skins/".$size."");
imagepng($thumb,"./skins/".$size."/".$id.".png");
$size = 5;
$thumb = create2d($img_src,$size);
//header("Content-Type: image/png");
@mkdir("./skins");
@mkdir("./skins/".$size."");
imagepng($thumb,"./skins/".$size."/".$id.".png");
return true;
}
/** 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;
}
?>

View File

@ -4,12 +4,12 @@ include 'functions.php';
$author = htmlentities(trim($_POST[author]));
$name = htmlentities(trim($_POST[name]));
$license = htmlentities(trim($_POST[license]));
$dataUrl = str_replace(' ', '+', $_POST[img]);
$dataUrl = str_replace(' ', '+', $_POST[img]); // the image will be injected via javascript and not using normal upload
$output = array('success' => false, 'status_msg' => 'UNKNOWN ERROR: could not save the Skin. unknown Error line 8');
$parts = explode(',', $dataUrl);
$bin = base64_decode($parts[1]);
$bin = base64_decode($parts[1]); //image injected as bas64 string now decoded as binary string
$size = getimagesizefromstring($bin);
$size = getimagesizefromstring($bin); // now at this point we get a GD object from base64 string image from uploaded injection
$output[img] = $size;
header('Content-Type: application/json');
@ -48,7 +48,7 @@ $query = mysql_query($sql);
$img = imagecreatefromstring($bin);
$id = mysql_insert_id();
$ok = save_images($img, $id);
$ok = save_images($img, $id); // this will genrate the 2d image plain view as a file into filesystem from the base64 image database, using a GD object image
if ($a == false) {
$output[success] = false;
$output[status_msg] = 'ERROR: could not save the Skin. Error in Mysql Sql says: {$a}';