Jump to content

Imagens PNG ficam com o fundo branco


Recommended Posts

Posted

Boas, tenho uma pequena função para upload da imagens.

Quando faço upload de jpg fica tudo bem, e de png's com fundo também, Mas notei que quando fiz upload de um logo sem fundo, ficou com o fundo branco.

<?php
class SimpleImage {
var $image;
var $image_type;

function load($filename) {

 $image_info = getimagesize($filename);
 $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { 
 $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) {
 $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) {
 $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
 if( $image_type == IMAGETYPE_JPEG ) {
 imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) {
 imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) {
 imagepng($this->image,$filename); } if( $permissions != null) {
 chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) {
 if( $image_type == IMAGETYPE_JPEG ) {
 imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) {
 imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) {
 imagepng($this->image); } } function getWidth() {
 return imagesx($this->image); } function getHeight() {
 return imagesy($this->image); } function resizeToHeight($height) {
 $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); }   function resizeToWidth($width) {
 $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); }   function scale($scale) {
 $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); }   function resize($width,$height) {
 $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; }   } ?>

<?php
if( isset($_POST['submit']) ) {

$valor_total = uniqid();
include('simpleimage2.php');
$image = new SimpleImage();
$image->load($_FILES['image'] ['tmp_name']);
$image2 = $_FILES['image']['name'];
$image->save('assets/img/sliders/revolution/'.$valor_total.$image2.'');

echo $query_select = "update slider set foto='assets/img/sliders/revolution/".$valor_total.$image2."' , titulo='".$_POST['titulo']."', descr ='".$_POST['descr']."' where id=1";
$result_select = mysql_query($query_select) or die(mysql_error());

 }

?>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.