getPreference() == "default") ? "steve" : "alex"; if ($user->getTexture($model_preferrnce) != "") { $src = imagecreatefrompng(BASE_DIR."/textures/".$user->getTexture($model_preferrnce)); $dest = imagecreatetruecolor(8, 8); $final = imagecreatetruecolor($size, $size); imagecopy($dest, $src, 0, 0, 8, 8, 8, 8); // Get image width and height $w = imagesx($src); $h = imagesy($src); // Turn alpha blending off imagealphablending($src, false); // Find the most opaque pixel in the image (the one with the smallest alpha value) $minalpha = 127; for($x = 0; $x < $w; $x++) for($y = 0; $y < $h; $y++) { $alpha = (imagecolorat($src, $x, $y) >> 24) & 0xFF; if ($alpha < $minalpha) { $minalpha = $alpha; } } // loop through image pixels and modify alpha for each for($x = 0; $x < $w; $x++) { for($y = 0; $y < $h; $y++) { // get current alpha value (represents the TANSPARENCY!) $colorxy = imagecolorat($src, $x, $y); $alpha = ($colorxy >> 24) & 0xFF; // calculate new alpha if ($minalpha !== 127) { $alpha = 127 + 127 * 1 * ($alpha - 127) / (127 - $minalpha); } else { $alpha += 127 * 1; } // get the color index with new alpha $alphacolorxy = imagecolorallocatealpha($src, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha); // set pixel with the new color + opacity imagesetpixel($src, $x, $y, $alphacolorxy); } } // The image copy imagecopy($dest, $src, 0, 0, 56, 8, 8, 8); imagecopyresized($final, $dest, 0, 0, 0, 0, $size, $size, 8, 8); header('Content-Type: image/png'); imagepng($final); imagedestroy($dest); imagedestroy($final); imagedestroy($src); } else { header('Content-Type: image/png'); echo Utils::fread(BASE_DIR."/assets/images/steve-avatar.png"); } } }