Imagem tamanho errado
Esse código.foi.tirado.da.serie.deartigos.do.Leandro.Vieira.sobre.Sistema.de.fotos.
Único.detalhes,é.que.na.hora.da.exibição.da.imagem,.ele.aumenta.a.imagem. Gostaria.de.saber.o.que.eu.tenho.que.tirar.para.que.na.hora.da.exibição.a.imagem
fique.no.tamanho.original.
<?php require_once('../Connections/connSisFotos.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
// Aqui, pegamos o nome e o nome temporário da imagem enviada.
$foto = $_FILES["foto_foto"]["name"];
$fotoTmp = $_FILES["foto_foto"]["tmp_name"];
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {// Acrescentamos o campo: foto_data.
// Em VALUES, alteramos o primeiro %s por '$foto'; e acrescentamos o comando NOW().
$insertSQL = sprintf("INSERT INTO fotos (foto_foto, foto_titulo, foto_legenda, foto_data) VALUES ('$foto', %s, %s, NOW())",
GetSQLValueString($_POST['foto_titulo'], "text"),
GetSQLValueString($_POST['foto_legenda'], "text"));
// Função que cria a imagem, não trabalharemos com upload.
function geraImg($img, $max_x, $max_y, $imgNome) {
//pega o tamanho da imagem ($original_x, $original_y)
list($width, $height) = getimagesize($img);
$original_x = $width;
$original_y = $height;
// se a largura for maior que altura acho a porcentagem
if($original_x > $original_y) {
$porcentagem = (100 * $max_x) / $original_x;
}
else {
$porcentagem = (100 * $max_y) / $original_y;
}
$tamanho_x = $original_x * ($porcentagem / 100);
$tamanho_y = $original_y * ($porcentagem / 100);
$image_p = imagecreatetruecolor($tamanho_x, $tamanho_y);
$image = imagecreatefromjpeg($img);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height);
return imagejpeg($image_p, $imgNome, 100);
}
// Chama a imagem, passando os parâmetros a ela.
geraImg($fotoTmp, 640, 480, "../fotos/".$foto);
mysql_select_db($database_connSisFotos, $connSisFotos);
$Result1 = mysql_query($insertSQL, $connSisFotos) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>Discussão (2)
Carregando comentários...