Fórum Ajuda - Processamento de Imagem #487434
30/07/2014
0
<br /> <b>Warning</b>: imagecreatefrompng(1406765838.png) [<a href='function.imagecreatefrompng'>function.imagecreatefrompng</a>]: failed to open stream: No such file or directory in <b>/home/Coestar/public_html/pixel.php</b> on line <b>17</b><br /> <br /> <b>Warning</b>: getimagesize(1406765838.png) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory in <b>/home/Coestar/public_html/pixel.php</b> on line <b>20</b><br /> <br /> <b>Warning</b>: imagecolorat() expects parameter 1 to be resource, boolean given in <b>/home/Coestar/public_html/pixel.php</b> on line <b>44</b><br /> <br /> <b>Warning</b>: imagecolorsforindex() expects parameter 1 to be resource, boolean given in <b>/home/Coestar/public_html/pixel.php</b> on line <b>44</b><br /> <br /> <b>Warning</b>: unlink(1406765838.png) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in <b>/home/Coestar/public_html/pixel.php</b> on line <b>60</b><br /> background-color: rgb(, , , 0); box-shadow: 0px 0px 0px transparent,
<?php
// Informa ao Navegador que isto é um Arquivo de Texto
Header('Content-Type: text/flat');
// Checa se o Upload foi Feito Corretamente
if($_FILES['texture']['error'] > 0)
die('Upload Error');
// Define o Nome Final da Imagem
$FinalName = time() . '.png';
// Move a Imagem
if(move_uploaded_file($_FILES['texture']['tmp_name'], $FinalName))
die('Error Moving Uploaded File');
// Carrega a Imagem
$Image = imagecreatefrompng($FinalName);
// Pega a Altura e Largura da Imagem
list($Width, $Height) = getimagesize($FinalName);
// Checa se o Tamanho é Maior que 320px
if(($Width > 320) || ($Height > 320))
unlink($FinalName) and die('Max Image Size: 320x320');
// Define o Tamanho de um Pixel
$wPixel = round(320 * $Width);
$hPixel = round(320 * $Height);
// Variável que Guardará o Código
$Code = '';
// Variáveis que vão Guardar as Coordenadas do Pixel Atual
$CurrentPixelW = 0;
$CurrentPixelH = 0;
// Varíaveis que vão Guardar o Tamanho do Pixel da CSS
$cPixelW = 0;
$cPixelH = 0;
// Loop
for($CurrentPixelW = 0; $CurrentPixelW <= $Width; $CurrentPixelW++){
for($CurrentPixelH = 0; $CurrentPixelH <= $Height; $CurrentPixelH++){
$Color = imagecolorsforindex($Image, imagecolorat($Image, $Width, $Height));
if(($CurrentPixelH == 0) && ($CurrentPixelW == 0))
$Code .= sprintf('background-color: rgb(%s, %s, %s, %s); box-shadow: %spx %spx 0px transparent, ',
$Color['red'], $Color['green'], $Color['blue'], round($Color['alpha'] * 1.27), $cPixelW, $cPixelH);
elseif(($CurrentPixelH == $Height) && ($CurrentPixelW == $Width))
$Code .= sprintf('%spx %spx 0px rgb(%s, %s, %s, %s);',
$cPixelW, $cPixelH, $Color['red'], $Color['green'], $Color['blue'], round($Color['alpha'] * 1.27));
else $Code .= sprintf('%spx %spx 0px rgb(%s, %s, %s, %s), ',
$cPixelW, $cPixelH, $Color['red'], $Color['green'], $Color['blue'], round($Color['alpha'] * 1.27));
$cPixelW += $wPixel;
}
$cPixelH += $hPixel;
$cPixelW = 0;
}
unlink($FinalName);
print($Code);Eu Revisei Várias Vezes e Não Achei o Erro :/
Mateus Ferreira
Curtir tópico
+ 0Posts
31/07/2014
Rafael Carrenho
Não consegui reproduzir exatamente as mesmas mensagens de erro mas percebi que o problema reside na declaração da variável $FinalName, coloque um path antes da função time(), deixando a declaração da variável da seguinte forma:
$FinalName = "/var/www/personal/DevMedia/images/".time() . '.png';
e lembre-se de deixar o diretório com o mesmo owner do apache (evite colocar um chmod 777, por segurança).
Gostei + 0
01/08/2014
Mateus Ferreira
Eu tentei mais não tive Resultados,
O Erro se Consiste no Upload, tentei em Outras Hospedagens e Nada :/
Gostei + 0
01/08/2014
Eduardo Martins
Então foi definido ali...
// Define o Nome Final da Imagem $FinalName = time() . '.png'; // Depois // Carrega a Imagem $Image = imagecreatefrompng($FinalName);
O erro que o php apresenta é ...
<br /> <b>Warning</b>: imagecreatefrompng(1406765838.png) [<a href='function.imagecreatefrompng'>function.imagecreatefrompng</a>]: failed to open stream: No such file or directory in <b>/home/Coestar/public_html/pixel.php</b> on line <b>17</b><br />
o Php vai tentar abrir a imagem 1406765838.png e não encontra. Não acha essa imagem na sua maquina, no seu hd.
A função image create from png, pega uma imagem que você já tem na sua máquina, para ai sim, realizar o tratamento dela.
Então primeiro você salva sua imagem no seu diretório, ai você vai conseguir pegar ela pela função imagecreatefrompng.
[]'s...
Gostei + 0
02/08/2014
Mateus Ferreira
disso eu Sei, meu Problema não está no 'imagecreatefrompng', e sim no Upload,
não estou Conseguindo Mover o Upload para a pasta Principal, com isso ocorre um erro no 'imagecreatefrompng'
Gostei + 0
04/08/2014
Eduardo Martins
Exemplo de Upload.
NO JS:
$('#form-photos').validate({
submitHandler: function( form ) {
if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
Alert.show('Seu navegador não tem suporte a arquivos.');
return;
}
input = document.getElementById('photos');
if (!input.files) {
Alert.show("Seu navegador não tem suporte a arquivos.");
}
else if (input.files.length == 0 && $('#id_photos').val() == 0) {
Alert.show("Selecione um arquivo para enviar!");
}
else {
for (var i=0, il=input.files.length; i<il; i++) {
file = input.files[i];
var xhr = new XMLHttpRequest();
if (xhr.upload && file.type == "image/jpeg" && file.size <= $("#MAX_FILE_SIZE").val()) {
$('#form-photos #photos_name').val( file.name );
xhr.onreadystatechange = function (e) {
console.log( 'onreadystatechange' );
if ( xhr.readyState === 4 ) {
if ( xhr.status === 200 ) {
console.log( xhr.responseText );
}
else {
console.log( "Error", xhr.statusText );
}
}
};
xhr.addEventListener("load", function(e) {
console.log( 'load' );
// depois q fez o upload da photo, salva no banco as informações necessárias.
// Photos.saveDB(form, 'save');
}, false);
xhr.upload.addEventListener("progress", function(e) {
console.log( 'progress' );
// apenas uma barra de progresso... não é necessário.
// Photos.progress(e);
}, false);
xhr.open("POST", 'upload.php', true);
xhr.setRequestHeader("X-FILENAME", file.name);
xhr.send( file );
}
};
}
return false;
}
});
NO PHP:
Upload em PHP, a pasta Photos deve estar criada. E dentro da pasta Photos criar a pasta Thumbs.
<?php
defined("DS") || define("DS", DIRECTORY_SEPARATOR);
defined("R" ) || define("R", dirname(__FILE__));
$photo_name = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ( $photo_name ) {
// save photo
file_put_contents('photos/' . $photo_name, file_get_contents('php://input'));
// create photo
// ************************************************
$photo_dir = R . DS . "photos" . DS;
$new_width = 800;
// ************************************************
// load image and get image size
$img = imagecreatefromjpeg( $photo_dir . $photo_name );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate photo size
$new_height = floor( $height * ( $new_width / $width ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// save photo into a file
imagejpeg( $tmp_img, $photo_dir . DS . $photo_name, 100 );
// ************************************************
// ************************************************
// ************************************************
// ************************************************
// ************************************************
// create Thumbs
// ************************************************
$photo_dir = R . DS . "photos" . DS;
$new_width = 300;
// ************************************************
// load image and get image size
$img = imagecreatefromjpeg( $photo_dir . $photo_name );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_height = floor( $height * ( $new_width / $width ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, $photo_dir . 'thumbs' . DS . $photo_name );
echo true;
exit;
}
echo false;
?>
Gostei + 0
05/08/2014
Mateus Ferreira
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)