Nähere Infos könnten hier helfen.Natürlich springt auch ne kleine belohnung raus
Für mich sieht das eher so aus, als wolltest du nen fertigen Script haben...Also ich brauch ein bisschen hilfe in sachen php bildbearbeitung.
Keine Angst ich für meinen Teil halt von DDrace genauso viel wie von City :P beides fürn Kübel
Ganz Ehrlich?
Hast du auch mal an Kritik gedacht?
Was er verbessern kann?
Was er falsch gemacht hat?
Welche Bilde findest du insbesondere schlecht?
Benutzerinformationen überspringen
Wohnort: http://goo.gl/bwF1X
Ingame-Name: Formeo [DE]
Renommeemodifikator: 11
PHP-Quelltext |
|
1 2 |
$skin = imagecreatefrompng('skin.png');
$output = imagecreatetruecolor(256, 128);
|
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Prototyp206« (10. März 2013, 14:59)
Benutzerinformationen überspringen
Wohnort: http://goo.gl/bwF1X
Ingame-Name: Formeo [DE]
Renommeemodifikator: 11
@ Malachite nein das war nich grad hilfreich ...
Benutzerinformationen überspringen
Wohnort: http://goo.gl/bwF1X
Ingame-Name: Formeo [DE]
Renommeemodifikator: 11
Benutzerinformationen überspringen
Wohnort: http://goo.gl/bwF1X
Ingame-Name: Formeo [DE]
Renommeemodifikator: 11
PHP-Quelltext |
|
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 |
/*
* UNGETESTET!!
*/
$skin = imagecreatefrompng('skin.png');
$output = imagecreatetruecolor(/* Bildgröße */);
$srcCoords = array( // Hier Positionen und Größen der Körperteile im Skin einfügen. Vierelementige Arrays mit X, Y, Breite, Höhe. Hinterster Körperteil zuerst.
'leftfoot' =>array(),
'body' => array(),
'lefteye' => array(),
'righteye' => array(),
'rightfoot' => array()
);
$destCoords = array( // Hier Positionen der Körperteile im Output einfügen. Zweielementige Arrays mit X, Y. Reihenfolge egal.
'lefteye' => array(),
'righteye' => array(),
'body' => array(),
'leftfoot' => array(),
'rightfoot' => array()
);
foreach ($srcCoords as $part => $src) {
$dest = $destCoords[$part];
imagecopy($output, $skin, $dest[0], $dest[1], $src[0], $src[1], $src[2], $src[3]);
}
|
PHP-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
list($width, $height, $type, $attr) = getimagesize("image_name.jpg"); // sperichert höhe und breite in variablen
if($width == 256 && $height == 128)
{
CreatePreView("image_name"); // mögliche funktion um die vorschau zu erstellen
}
else
{
CreateThumbnail("image_name"); // mögliche funktion um thumbnail zu erstellen
}
// dein skript um preview zu erstellen
CreatePreView(string sImageName)
{
// erstelle prev
}
// dein skript um thumbnail zu erstellen
CreateThumbnail(string sImageName)
{
// erstelle thumb
}
|
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »0!=1« (10. März 2013, 17:41)
PHP-Quelltext |
|
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
function create_new_thumb($picturepath) {
global $jlistConfig;
jimport('joomla.filesystem.folder');
$thumbpath = JPATH_SITE.'/images/jdownloads/screenshots/thumbnails/';
if (!is_dir($thumbpath)){
JFolder::create("$thumbpath", 0755);
}
$newsize = $jlistConfig['thumbnail.size.width'];
$thumbfilename = $thumbpath.basename($picturepath);
if (file_exists($thumbfilename)){
return true;
}
/* Prüfen ob Datei existiert */
if(!file_exists($picturepath)) {
return false;
}
/* MIME-Typ auslesen */
$size=getimagesize($picturepath);
switch($size[2]) {
case "1":
$oldpic = Imagecreatefromgif($picturepath);
break;
case "2":
$oldpic = Imagecreatefromjpeg($picturepath);
break;
case "3":
$oldpic = Imagecreatefrompng($picturepath);
break;
default:
return false;
}
/* Alte Maße auslesen */
$width = $size[0];
$height = $size[1];
$maxwidth = $jlistConfig['thumbnail.size.width'];
$maxheight = $jlistConfig['thumbnail.size.height'];
if ($width/$maxwidth > $height/$maxheight) {
$newwidth = $maxwidth;
$newheight = $maxwidth*$height/$width;
} else {
$newheight = $maxheight;
$newwidth = $maxheight*$width/$height;
}
/* Neues Bild erstellen mit den neuen Maßen */
$newpic = Imagecreate($newwidth,$newheight);
/* Jetzt wird das Bild nur noch verkleinert */
imagecopyresampled($newpic,$oldpic,0,0,0,0,$newwidth,$newheight,$width,$height);
// Bild speichern
switch($size[2]) {
case "1": return imagegif($newpic, $thumbfilename);
break;
case "2": return imagejpeg($newpic, $thumbfilename);
break;
case "3": return imagepng($newpic, $thumbfilename);
break;
}
//Bilderspeicher freigeben
imagedestroy($oldpic);
imagedestroy($newpic);
}
function create_new_image($picturepath) {
global $jlistConfig;
jimport('joomla.filesystem.folder');
$thumbpath = JPATH_SITE.'/images/jdownloads/screenshots/';
if (!is_dir($thumbpath)){
JFolder::create("$thumbpath", 0755);
}
$newsize = $jlistConfig['create.auto.thumbs.from.pics.image.width'];
$thumbfilename = $thumbpath.basename($picturepath);
if (file_exists($thumbfilename)){
return true;
}
/* Pruefen ob Datei existiert */
if(!file_exists($picturepath)) {
return false;
}
/* MIME-Typ auslesen */
$size=getimagesize($picturepath);
switch($size[2]) {
case "1":
$oldpic = Imagecreatefromgif($picturepath);
break;
case "2":
$oldpic = Imagecreatefromjpeg($picturepath);
break;
case "3":
$oldpic = Imagecreatefrompng($picturepath);
break;
default:
return false;
}
/* Alte Groesse auslesen */
$width = $size[0];
$height = $size[1];
/* Neue Groesse errechnen */
$maxwidth = $jlistConfig['create.auto.thumbs.from.pics.image.width'];
$maxheight = $jlistConfig['create.auto.thumbs.from.pics.image.height'];
if ($width/$maxwidth > $height/$maxheight) {
$newwidth = $maxwidth;
$newheight = $maxwidth*$height/$width;
} else {
$newheight = $maxheight;
$newwidth = $maxheight*$width/$height;
}
$newpic = Imagecreate($newwidth,$newheight);
imagealphablending($newpic,false);
imagesavealpha($newpic,true);
/* Jetzt wird das Bild nur noch verkleinert */
imagecopyresampled($newpic,$oldpic,0,0,0,0,$newwidth,$newheight,$width,$height);
// Bild speichern
switch($size[2]) {
case "1": return imagegif($newpic, $thumbfilename);
break;
case "2": return imagejpeg($newpic, $thumbfilename);
break;
case "3": return imagepng($newpic, $thumbfilename);
break;
}
//Bilderspeicher freigeben
imagedestroy($oldpic);
imagedestroy($newpic);
}
|
PHP-Quelltext |
|
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
<?php
/**
* Tee Preview Generation Script
* by Alban 'spl0k' FERON
*
* This file can be used to generate previews of the Teeworlds skins.
* It takes a png skin file, create a preview png file, and display it.
* I assumed that all the skin files have a size of 256x128 pixels.
* It uses the PHP GD library.
*
* -- USAGE --
* First, include this file in your website code.
* Then, just call the display_tee() function with the path of the skin file.
* i.e if you have a skin stored like that: path/to/your/skin.png, the call would be like
* display_tee("path/to/your/skin.png");
* It will create a new file: path/to/your/previews/skin.png
* Finally, it'll add the <img> tag.
* The previews aren't regenerated when a skin file is modified, you have to manually delete
* the preview file for this script to recreate it.
*
* -- REQUIREMENTS --
* PHP 4 or PHP 5
* PHP must be compiled with the GD library or the GD module must be active.
* If your site is hosted on a *nix based system, be sure to 'chmod o+w' the folder where
* you put your skins.
*
* -- CREDITS --
* This script was developed by spl0k for the teeworlds-db site.
*
* http://www.teeworlds.com/
* http://www.teeworlds-db.com/
* http://spl0k.unreal-design.com/
*/
/**
* Draw a body part centered
*
* @param dest (reference) - the image resource object to paint on
* @param src (reference) - the image resource object of the skin
* @param sprite - the name of the part to draw
* @param x - the X component of the center where to draw
* @param y - the Y component of the center where to draw
* @param w - the width of the part on the destination image
* @param h - the height of the part on the destination image
* @return a image resource object if successful, FALSE otherwise
*/
function gfx_draw(&$dest, &$src, $sprite, $x, $y, $w, $h) {
// Positions of the parts on the skin. We assume that the skin size is 256x128
switch($sprite) {
case "body":
$srcx = 0;
$srcy = 0;
$srcw = 96;
$srch = 96;
break;
case "body_shadow":
$srcx = 96;
$srcy = 0;
$srcw = 96;
$srch = 96;
break;
case "foot":
$srcx = 192;
$srcy = 32;
$srcw = 64;
$srch = 32;
break;
case "foot_shadow":
$srcx = 192;
$srcy = 64;
$srcw = 64;
$srch = 32;
break;
case "eye":
case "eye2":
$srcx = 64;
$srcy = 96;
$srcw = 32;
$srch = 32;
break;
}
// Since the GD doesn't know to mirror images (negative resizing), we have
// to do it by hand
if($sprite == "eye2") {
// First we create a temp image with just the eye
$im = imagecreatetruecolor(32, 32);
imagealphablending($im, false);
imagecopy($im, $src, 0, 0, $srcx, $srcy, $srcw, $srch);
// We mirror it...
$im = mirror_x($im);
// and we draw it on the tee.
return imagecopyresampled($dest, $im, $x-$w/2, $y-$h/2, 0, 0, $w, $h, $srcw, $srch);
}
return imagecopyresampled($dest, $src, $x-$w/2, $y-$h/2, $srcx, $srcy, $w, $h, $srcw, $srch);
}
/**
* Mirror an image
* Code snippet from php.net site, by send at mail dot 2aj dot net.
* Modified to mirror the X axis and not the Y axis.
*
* @see http://php.net/manual/function.imagecreatetruecolor.php#54155
* @param input_image_resource - the image to mirror
* @return the mirrored image
*/
function mirror_x($input_image_resource)
{
$width = imagesx ( $input_image_resource );
$height = imagesy ( $input_image_resource );
$output_image_resource = imagecreatetruecolor ( $width, $height );
// If a pixel was transparent on the input, set it to transparent on the output too
imagealphablending($output_image_resource, false);
$x = 0;
while ( $x < $width )
{
for ( $i = 0; $i < $height; $i++ )
imagesetpixel ( $output_image_resource, $x, $i, imagecolorat ( $input_image_resource, ( $width - 1 - $x ), ( $i ) ) );
$x++;
}
return $output_image_resource;
}
/**
* Extract the parts from the skin image and build the tee
* This function is adapted from Teeworlds game code (gc_render.cpp, render_tee(), line 137)
*
* @param dest (reference) - the image resource object to paint on
* @param src (reference) - the image resource object of the skin
* @return TRUE if fully drawn, FALSE otherwise
*/
function paint(&$dest, &$src) {
// Position of the center of the tee in the new image
$position_x = 48.0;
$position_y = 56.0;
// first pass we draw the outline
// second pass we draw the filling
for($p=0; $p<2; $p++)
{
$outline = ($p==0);
for($f=0; $f<2; $f++)
{
// 96.0 is the default tee size.
$animscale = 96.0 * 1.0/64.0;
$basesize = 96.0;
if($f == 1)
{
// draw body
$body_pos_x = $position_x;
$body_pos_y = $position_y - 4.0 * $animscale;
$sprite = $outline?"body_shadow":"body";
if(!gfx_draw($dest, $src, $sprite, $body_pos_x, $body_pos_y, $basesize, $basesize))
return false;
// draw eyes
if($p == 1)
{
$sprite = "eye";
$eyescale = $basesize*0.40;
$h = $eyescale;
$eyeseparation = (0.075 - 0.010)*$basesize;
$offset_x = 0.125 * $basesize;
$offset_y = -0.05 * $basesize;
if(!gfx_draw($dest, $src, $sprite, $body_pos_x-$eyeseparation+$offset_x, $body_pos_y+$offset_y, $eyescale, $h) ||
!gfx_draw($dest, $src, $sprite."2", $body_pos_x+$eyeseparation+$offset_x, $body_pos_y+$offset_y, $eyescale, $h))
return false;
}
}
// draw feet
$w = $basesize;
$h = $basesize/2;
if($outline)
$sprite = "foot_shadow";
else
$sprite = "foot";
if(!gfx_draw($dest, $src, $sprite, $position_x+($f==0?-7.0:7.0)*$animscale, $position_y+10.0*$animscale, $w, $h))
return false;
}
}
return true;
}
/**
* Create the preview file
*
* @param file - path to the skin file
* @return TRUE if successful, FALSE otherwise
*/
function create_tee($file) {
// load the skin file
$src = @imagecreatefrompng($file);
if($src === false)
return false;
// Create the preview image and set its background transparent
$dest = imagecreatetruecolor(96, 96);
$back = imagecolorallocatealpha($dest, 255, 255, 255, 127);
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagefill($dest, 0, 0, $back);
// Reactivate alpha blending to not erase other layers when drawing a new body part
imagealphablending($dest, true);
// Generating the Tee.
if(!paint($dest, $src))
return false;
// Saving the image to the disk.
if(!@imagepng($dest, dirname($file)."/previews/".basename($file)))
return false;
// Freeing memory
imagedestroy($src);
imagedestroy($dest);
return true;
}
/**
* Main function, take a path to a skin file, generate the preview if needed and display it.
* The folder you put your skins in must be writable by all users in order for the script
* to create the preview folder.
* If there's a problem creating the preview folder or the preview itself, it displays nothing
*
* @param file - The path to the skin file
* @return TRUE if successful, FALSE if there's a problem
*/
function display_tee($file) {
// Check if the previews folder exists. If not, create it and generate the preview
if(!is_dir(dirname($file)."/previews")) {
if(!@mkdir(dirname($file)."/previews"))
return false;
@chmod(dirname($file)."/previews", 0777);
if(!create_tee($file))
return false;
}
// else if the folder exists but not the preview, generate it
else if(!is_file(dirname($file)."/previews/".basename($file))) {
if(!create_tee($file))
return false;
}
// display the preview
echo "<a href="".dirname($file)."/".basename($file)."" alt="".basename($file)."" />
<img src="".dirname($file)."/previews/".basename($file)."" alt="".basename($file)."" />";
echo "".basename($file).PHP_EOL;
echo "</p>";
}
?>
|