Jump to content
php.lv forumi

Ka saglabat jpg bildi failaa?


Janhouse

Recommended Posts

tatad man te nelies skriptins, kurs samazina bildi:

<?php
// File and new size
$filename = '1.jpg';


// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = 100;
$newheight = 80;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

 

Ka izveidoto bildi saglabat kada mapite uz servera?

Link to comment
Share on other sites

Laikam tomēr kļūdījos! Neesmu visu atrisinājis. Tikutik tālu ar upload, kurš strādāperfekti:

 

$uploaddir = 'pictures/users/avatars/';

$veidz=$_FILES['userfile']['type'];

//$fails=$_FILES['userfile']['name'];
if ($veidz=="image/jpeg" or $veidz=="image/bmp" or $veidz=="image/png"){

$damn="$idIN.jpg";
$_FILES['userfile']['name']=$damn;
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Fails tika veiksmīgi ielādēts uz servera.\n";
}
else
{
print"Failu neizdevās ielādēt uz servera!";
}
}
else
{
print"Faila formāts neatbilsts! Var ielādēt tikai .jpg, .bmp un .png formāta bildes.";

//echo 'Here is some more debugging info:';
//print_r($_FILES);
}

 

Bet nesaprotu, kā tajā kodā piemontēt to samazināšanas skriptiņu...

 

<?php
// Content type
header('Content-type: image/jpeg');

// File and new size
$id = $HTTP_GET_VARS['id'];
$filename = "$id.jpg";
$adreseJOU="pictures/users/avatars/$id.jpg";

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = 100;
$newheight = 80;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
//imagejpeg($thumb, $adreseJOU);

imagejpeg($thumb);
?>

 

[/b]Tas header('Content-type: image/jpeg'); visu prieku bojā, bet bez tā tak nekādīgi. :) [/b]

Link to comment
Share on other sites

×
×
  • Create New...