guarana1 Posted February 20, 2014 at 04:45 PM Report #545955 Posted February 20, 2014 at 04:45 PM 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()); } ?>
HappyHippyHippo Posted February 20, 2014 at 05:15 PM Report #545958 Posted February 20, 2014 at 05:15 PM era suposto se conseguir ler esse código ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
guarana1 Posted February 20, 2014 at 06:35 PM Author Report #545977 Posted February 20, 2014 at 06:35 PM era suposto se conseguir ler esse código ? 😄 Copiei o código de uma página, e ficou tudo na mesma linha. Ainda tentei por ai uns paragrafos. fui buscar o código aqui (no site lê-se bastante melhor 🙂 ) http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
yoda Posted February 20, 2014 at 06:40 PM Report #545978 Posted February 20, 2014 at 06:40 PM http://stackoverflow.com/questions/32243/can-png-image-transparency-be-preserved-when-using-phps-gdlib-imagecopyresample before you post, what have you tried? - http://filipematias.info sense, purpose, direction
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now