Forum Moderators: coopster
<?php
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
$image=imagecreatetruecolor( $width ,$height );
$background = imagecolorallocate( $image ,0 , 0 , 0 );
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
$int = hexdec($data[$i++]);
$color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
imagesetpixel ( $image , $x , $y , $color );
}
}
//Output image and clean
header( "Content-type: image/jpeg" );
ImageJPEG( $image );
imagedestroy( $image );
?>
<?php
//get the session id from the flash movie
session_id($_POST['myID']);
session_start();
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
$image=imagecreatetruecolor( $width ,$height );
$background = imagecolorallocate( $image ,0 , 0 , 0 );
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
$int = hexdec($data[$i++]);
$color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
imagesetpixel ( $image , $x , $y , $color );
}
}
$today = date("Ymdgi");
//Output image and clean
$save = '../images/cars/'.$today.'_'.$_SESSION['username'].'.jpg';
header( "Content-type: image/jpeg" );
ImageJPEG( $image, $save, 100 );
imagedestroy( $image );
?>
<?php
//get the session id from the flash movie
session_id($_POST['myID']);
session_start();
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
$image=imagecreatetruecolor( $width ,$height );
$background = imagecolorallocate( $image ,0 , 0 , 0 );
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
$int = hexdec($data[$i++]);
$color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
imagesetpixel ( $image , $x , $y , $color );
}
}
//generate todays date and time for the filename
$today = date("Ymdgi");
//combine date and username
$filename = $today.'_'.$_SESSION['username'];
//Output image and save it with the filename we generated
$save = '../images/cars/'.$filename.'.jpeg';
header( "Content-type: image/jpeg" );
ImageJPEG( $image, $save, 100 );
//clean up
imagedestroy( $image );
$thumb = '../images/cars/'.$filename.'.jpeg';
$new_thumb = imagecreatefromjpeg($thumb);
//list the width and height and keep the height ratio.
list($srcwidth, $srcheight) = getimagesize($thumb);
//calculate the new size
$newwidth = $srcwidth / 2;
$newheight = $srcheight / 2;
$new_thumb = imagecreatetruecolor($newwidth,$newheight);
//the resizing is going on here!
imagecopyresized($new_thumb, $thumb, 0, 0, 0, 0, $newwidth, $newheight, $srcwidth, $srcheight);
$thumbsave = '../images/cars/thumbs/'.$filename.'.jpeg';
header( "Content-type: image/jpeg" );
ImageJPEG( $new_thumb, $thumbsave, 100 );
//clean up
imagedestroy( $new_thumb );
?>
/**
*
* Redimensionar e salvar uma imagem
* Resize and save an image
*
* @author Miguel Koscianski Vidal - miguelvidal@siscompar.com.br
* @since 2010-02-01
*
* Seja Honesto! - Be honest!
*
* Ao utilizar um código criado por terceiros, mantenha os créditos do autor original.
* Ao modificar um código criado por terceiros, mantenha os créditos do autor do código adicionando as informações e créditos relativas à sua modificação.
*
* If you use any code made by another person, don't remove the author's information.
* If you modify any code made by another person, don't remove the author's information and add yours.
*
* Respeite seu idioma e sua nação! - Respect your language and your nation!
*
* Ao produzir qualquer material, sempre que possível faça-o em sua língua materna respeitando a língua culta e correta (sem erros!).
* Adicione tradução para todos os idiomas que quiser, mas não remova o original que deveria ser feito em sua língua materna.
*
* When producing any material, whenever possible make it in your native language respecting the cultured and correct language rules (without errors!).
* Add translation for all languages you want, but do not remove the original that should be done in your native language.
*
*/
$imagem = "/caminho/da/imagem.jpg" // deve ser JPG - must be JPG
$nome = "minha_imagem.jpg" // nome que será salvo - name to save
$destino = "/onde/salvar/" // atenção na '/' final - notice the final '/'
{
// largura e altura máximos - max width and height
$lMax = 150;
$aMax = 150;
// valores que serão usados na nova imagem - values used in the nwe image
$largura = 0;
$altura = 0;
$novaImagem = imagecreatefromjpeg( "{$imagem}" ); // newImg = create!
// largura e altura originais (da imagem) - original width and height (of the image)
$lOri = imagesx( $novaImagem );
$aOri = imagesy( $novaImagem );
$largura = $lOri;
$altura = $aOri;
//redimensionando... - resizing...
if( $lOri > $lMax || $aOri > $aMax )
{
$largura = $lMax;
$altura = ( $largura / $lOri ) * $aOri;
if( $altura > $aMax )
{
$altura = $aMax;
$largura = ( $altura / $aOri ) * $lOri;
}
}
// criando e salvando a imagem - creating and saving the image
$tmpImagem = imagecreatetruecolor( $largura, $altura );
imagecopyresampled( $tmpImagem, $novaImagem, 0, 0, 0, 0, $largura,
$altura, $lOri, $aOri );
imagejpeg( $tmpImagem, "{$destino}{$nome}" );
$tmpImagem = imagecreatetruecolor( $largura, $altura );
imagecopyresized( $tmpImagem, $novaImagem, 0, 0, 0, 0, $largura,
$altura, $lOri, $aOri );
imagejpeg( $tmpImagem, "{$destino}{$nome}" );
}