Ir para conteúdo
Fórum Script Brasil

lags cap

Membros
  • Total de itens

    7
  • Registro em

  • Última visita

Tudo que lags cap postou

  1. Olá, com o código abaixo eu recebo uma imagem através de um formulário em uma página html, faço alguns cortes nela e adiciono outra imagem à ela, isso está funcionando perfeitamente. Estou com problemas de caracteres especiais no nome da imagem que recebo do form html... Resumindo, antes de fazer o upload, cortar as imagens, movê-las, etc, preciso tratar o nome delas... retirar espaços e parênteses, retirar acentos, etc.. Eu tentei utilizar algumas funções mas sem sucesso.. não consegui resolver, alguém pode dar uma ajuda? Segue meu código: <?php require( "./lib/WideImage.php"); // Example of accessing data for a newly uploaded file $fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // Path and file name $pathAndName = "cartelas/cart".$fileName; // Run the move_uploaded_file() function here $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); // Evaluate the value returned from the function if needed $image = WideImage::load($pathAndName); $unh = WideImage::load("unh11.png"); $crop1 = $image->crop("25", "50", 111, 132); $out1 = $crop1->merge($unh,'middle','middle'); $pathAndName1 = "unha-1-".$fileName; $crop1->saveToFile('./cartelas/estampa'.$pathAndName1); $out1->saveToFile('./cartelas/'.$pathAndName1); echo "Imagens geradas:<BR>"; echo "<img src=./cartelas/estampa$pathAndName1><img src=./cartelas/$pathAndName1>"; ?> Tentei utilizar esta função: function tratar_arquivo_upload($string){ // pegando a extensao do arquivo $partes = explode(".", $string); $extensao = $partes[count($partes)-1]; // somente o nome do arquivo $nome = preg_replace('/\.[^.]*$/', '', $string); // removendo simbolos, acentos etc $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýýþÿ???'; $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuuyybyRr-'; $nome = strtr($nome, utf8_decode($a), $b); $nome = str_replace(".","-",$nome); $nome = preg_replace( "/([^0-9a-zA-Z\.])+/",'-',$nome); return utf8_decode(strtolower($nome.".".$extensao)); } $arquivo_tratado = tratar_arquivo_upload(utf8_decode(pathAndName1)); Mas também não consegui... Alguma ajuda?
  2. lags cap

    Ajuda com LOOPS

    Não, não retornou nenhum erro. Apenas não teve nenhum resultado do que programei para fazer com a Wide Image. eu coloquei uns echo"testes"; pelo código e não vi nada de anormal...
  3. lags cap

    Ajuda com LOOPS

    foi PERFEITO! Mas infelizmente não funcionou :unsure: Talvez esta classe WideImage não permita este tipo de chamada usando Arrays e etc, ou estou falando besteira? Segue meu código: <?php require( "./lib/WideImage.php"); // Example of accessing data for a newly uploaded file $fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // Path and file name $pathAndName = "cartelas/cart".$fileName; // Run the move_uploaded_file() function here $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); // Evaluate the value returned from the function if needed $image = WideImage::load($pathAndName); $unh = WideImage::load("unh11.png"); $dadosCrops = array( array(25,50), // x,y do crop1 array(619,50), // x,y do crop2 array(25,326), // x,y do crop3 array(619,326), // x,y do crop4 array(25,869), // x,y do crop5 array(619,869), // x,y do crop6 array(25,1147), // x,y do crop7 array(619,1147), // x,y do crop8 array(25,1417), // x,y do crop9 array(619,1417), // x,y do crop10 ); $crops = array(); $outs = array(); $paths = array(); echo "Imagens geradas:<BR><BR>"; foreach($dadosCrops as $i => $dados) { $crops[$i] = $image->crop($dados[0], $dados[1], 111, 132); $outs[$i] = $crops[$i]->merge($unh,'middle','middle'); $j = $i+1; // pra usar 1-2-3-4-5 ao invés de 0-1-2-3 etc $paths[$i] = "unha-$j-".$filename; $crops[$i]->saveToFile('./cartelas/estampa'.$paths[$i]); $outs[$i]->saveToFile('./cartelas/'.$paths[$i]); echo "<img src=./cartelas/estampa$paths[$i]><img src=./cartelas/$paths[$i]><BR><BR>"; } ?>
  4. lags cap

    Ajuda com LOOPS

    PERFEITO! Melhor impossível, muito obrigado pela resposta, vou estudá-la e adaptá-la para o meu uso. Abraço!
  5. lags cap

    Ajuda com LOOPS

    Boa tarde. Preciso de uma ajudinha pra transformar este código sequencial em alguns loops. Alguém pode me dar uma luz? Este código eu desenvolvi utilizando a classe WideImage. Ele recebe de um formulário via POST uma imagem e faz alguns crops nela. Funcioca perfeitamente, gostaria apenas de melhorar o código. O código trabalha sempre com 10 imagens, e para isso utilizei 10 linhas, acho que poderia melhorar isso com algum WHILE ou algo do tipo... Agradeço a ajuda. <?php require( "./lib/WideImage.php"); // Example of accessing data for a newly uploaded file $fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // Path and file name $pathAndName = "cartelas/cart".$fileName; // Run the move_uploaded_file() function here $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); // Evaluate the value returned from the function if needed $image = WideImage::load($pathAndName); $unh = WideImage::load("unh11.png"); $crop1 = $image->crop("25", "50", 111, 132); $crop2 = $image->crop("619", "50", 111, 132); $crop3 = $image->crop("25", "326", 111, 132); $crop4 = $image->crop("619", "326", 111, 132); $crop5 = $image->crop("25", "595", 111, 132); $crop6 = $image->crop("619", "595", 111, 132); $crop6 = $image->crop("25", "869", 111, 132); $crop7 = $image->crop("619", "869", 111, 132); $crop7 = $image->crop("25", "1147", 111, 132); $crop8 = $image->crop("619", "1147", 111, 132); $crop9 = $image->crop("25", "1417", 111, 132); $crop10 = $image->crop("619", "1417", 111, 132); $out1 = $crop1->merge($unh,'middle','middle'); $out2 = $crop2->merge($unh,'middle','middle'); $out3 = $crop3->merge($unh,'middle','middle'); $out4 = $crop4->merge($unh,'middle','middle'); $out5 = $crop5->merge($unh,'middle','middle'); $out6 = $crop6->merge($unh,'middle','middle'); $out7 = $crop7->merge($unh,'middle','middle'); $out8 = $crop8->merge($unh,'middle','middle'); $out9 = $crop9->merge($unh,'middle','middle'); $out10 = $crop10->merge($unh,'middle','middle'); $pathAndName1 = "unha-1-".$fileName; $pathAndName2 = "unha-2-".$fileName; $pathAndName3 = "unha-3-".$fileName; $pathAndName4 = "unha-4-".$fileName; $pathAndName5 = "unha-5-".$fileName; $pathAndName6 = "unha-6-".$fileName; $pathAndName7 = "unha-7-".$fileName; $pathAndName8 = "unha-8-".$fileName; $pathAndName9 = "unha-9-".$fileName; $pathAndName10 = "unha-10-".$fileName; $crop1->saveToFile('./cartelas/estampa'.$pathAndName1); $crop2->saveToFile('./cartelas/estampa'.$pathAndName2); $crop3->saveToFile('./cartelas/estampa'.$pathAndName3); $crop4->saveToFile('./cartelas/estampa'.$pathAndName4); $crop5->saveToFile('./cartelas/estampa'.$pathAndName5); $crop6->saveToFile('./cartelas/estampa'.$pathAndName6); $crop7->saveToFile('./cartelas/estampa'.$pathAndName7); $crop8->saveToFile('./cartelas/estampa'.$pathAndName8); $crop9->saveToFile('./cartelas/estampa'.$pathAndName9); $crop10->saveToFile('./cartelas/estampa'.$pathAndName10); $out1->saveToFile('./cartelas/'.$pathAndName1); $out2->saveToFile('./cartelas/'.$pathAndName2); $out3->saveToFile('./cartelas/'.$pathAndName3); $out4->saveToFile('./cartelas/'.$pathAndName4); $out5->saveToFile('./cartelas/'.$pathAndName5); $out6->saveToFile('./cartelas/'.$pathAndName6); $out7->saveToFile('./cartelas/'.$pathAndName7); $out8->saveToFile('./cartelas/'.$pathAndName8); $out9->saveToFile('./cartelas/'.$pathAndName9); $out10->saveToFile('./cartelas/'.$pathAndName10); echo "Imagens geradas:<BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName1><img src=./cartelas/$pathAndName1><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName2><img src=./cartelas/$pathAndName2><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName3><img src=./cartelas/$pathAndName3><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName4><img src=./cartelas/$pathAndName4><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName5><img src=./cartelas/$pathAndName5><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName6><img src=./cartelas/$pathAndName6><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName7><img src=./cartelas/$pathAndName7><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName8><img src=./cartelas/$pathAndName8><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName9><img src=./cartelas/$pathAndName9><BR><BR>"; echo "<img src=./cartelas/estampa$pathAndName10><img src=./cartelas/$pathAndName10><BR><BR>"; ?>
  6. lags cap

    PHP GD - juntar fotos

    Olá Consegui editar uma classe para unir as imagens que preciso. Agora basta SALVAR esta imagem no pc após gerá-la Não estou conseguindo salvar, o código gera perfeitamente mas não copia a imagem para o pc. Segue o código: <?php $sprite = new spritify(); $files = glob("test_images/10-*home*.*"); for ($i=1; $i<count($files); $i++) { $num = $files[$i]; $sprite->add_image($num, "jpeg"); //echo $num; } //retrieving error $arr = $sprite->get_errors(); //if there are any then output them if(!empty($arr)) { foreach($arr as $error) { echo "<p>".$error."</p>"; } } else { //returns GD image resource //$img = $sprite->get_resource(); //outputs image to browser $sprite->output_image(); } /************************************************************* * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com * Fee free to distribute and modify code, but keep reference to its creator * * This class can generate CSS sprite image from multiple provided images * Generated image can be outputted to browser, saved to specified location, etc. * This class also generates CSS code for sprite image, using element ID's provided with image. * It facilitates CSS sprite implementations to existing website structures * * For more information, examples and online documentation visit: * http://webcodingeasy.com/PHP-classes/CSS-sprite-class-for-creating-sprite-image-and-CSS-code-generation **************************************************************/ class spritify { //image type to save as (for possible future modifications) private $image_type = "png"; //array to contain images and image informations private $images = array(); //array for errors private $errors = array(); //gets errors public function get_errors(){ return $this->errors; } /* * adds new image * first parameter - path to image file like ./images/image.png * second parameter (optiona) - ID of element fro css code generation */ public function add_image($image_path, $id="elem"){ if(file_exists($image_path)) { $info = getimagesize($image_path); if(is_array($info)) { $new = sizeof($this->images); $this->images[$new]["path"] = $image_path; $this->images[$new]["width"] = $info[0]; $this->images[$new]["height"] = $info[1]; $this->images[$new]["mime"] = $info["mime"]; $type = explode("/", $info['mime']); $this->images[$new]["type"] = $type[1]; $this->images[$new]["id"] = $id; } else { $this->errors[] = "Provided file \"".$image_path."\" isn't correct image format"; } } else { $this->errors[] = "Provided file \"".$image_path."\" doesn't exist"; } } //calculates width and height needed for sprite image private function total_size(){ $arr = array("width" => 0, "height" => 0); foreach($this->images as $image) { if($arr["height"] < $image["height"]) { $arr["height"] = $image["height"]; } $arr["width"] += $image["width"]; } return $arr; } //creates sprite image resource private function create_image(){ $total = $this->total_size(); $sprite = imagecreatetruecolor($total["width"], $total["height"]); imagesavealpha($sprite, true); $transparent = imagecolorallocatealpha($sprite, 0, 0, 0, 127); imagefill($sprite, 0, 0, $transparent); $top = 0; $side = 0; foreach($this->images as $image) { $func = "imagecreatefrom".$image['type']; $img = $func($image["path"]); imagecopy( $sprite, $img, $side, ($total["height"] - $image["height"]), 0, 0, $image["width"], $image["height"]); //imagecopy( $sprite, $img, ($total["width"] - $image["width"]), $top, 0, 0, $image["width"], $image["height"]); $top += $image["height"]; $side += $image["width"]; } return $sprite; } //outputs image to browser (makes php file behave like image) public function output_image(){ $sprite = $this->create_image(); header('Content-Type: image/'.$this->image_type); $func = "image".$this->image_type; $func($sprite); ImageDestroy($sprite); } /* * generates css code using ID provided when adding images or pseido ID "elem" * $path parameter (optional) - takes path to already generated css_sprite file or uses default file for pseudo code generation */ public function generate_css($path = "/css_sprite.png"){ $total = $this->total_size(); $top = $total["height"]; $css = ""; foreach($this->images as $image) { if(strpos($image["id"],"#") === false) { $css .= "#".$image["id"]." { "; } else { $css .= $image["id"]." { "; } $css .= "background-image: url(".$path."); "; $css .= "background-position: ".($image["width"] - $total["width"])."px ".($top - $total["height"])."px; "; $css .= "width: ".$image['width']."px; "; $css .= "height: ".$image['height']."px; "; $css .= "}\n"; $top -= $image["height"]; } return $css; } /* * if $path provided, than saves image to path * else forces image download */ public function safe_image($path = ""){ $sprite = $this->create_image(); $func = "image".$this->image_type; if(trim($path) == "") { header('Content-Description: File Transfer'); header('Content-Type: image/'.$this->image_type); header('Content-Disposition: attachment; filename=css_sprite.'.$this->image_type); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($sprite)); ob_clean(); flush(); $func($sprite); } else { $func($sprite, $path); } ImageDestroy($sprite); } //return image resource public function get_resource(){ $sprite = $this->create_image(); return $sprite; } } ?>
  7. Boa tarde amigos, já revirei a internet a procura de uma função que utilize a biblioteca GD para unir vários arquivos de imagem em um só, mas não encontrei nada. Alguém pode sugerir um? Preciso de uma função que pegue todas as imagens de um diretório "x" e una-as uma ao lado da outra, na horizontal. Testei alguns scripts mas nada funcionou. Caso alguém conheça, preciso gerar estas imagens para trabalhar com CSS SPRITES. Grato
×
×
  • Criar Novo...