Значи, имам скрипт който качва картинки в определена директория..
Ето това е upload.php
ии.. искам след като се ъплоудне картинката да се изпълнява този код (той да смалява ъплоуднатата картинка)..
мн. ще съм ви благодарен ако ми кажете как ще стане :roll: :arrow:
Ето това е upload.php
Код:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<HEAD>
<TITLE></TITLE>
</HEAD>
<body bgcolor="#F0F0F0">
<center>
<?php
$dossier = "images";
$MaxSize = 100000;
$Maxwidth = 1000;
$Maxheight = 1000;
$ValidType = array("image/gif"=>"gif","image/pjpeg"=>"jpg","image/jpeg"=>"jpg","image/png"=>"png");
if(!isset($_FILES['upload'])) exit("upload absent <a href=index.html>[Charger une nouvelle image]</a>");
if($_FILES['upload']['size'] > $MaxSize) exit("Image trop lourde <a href=index.html>[Charger une nouvelle image]</a>");
$infos_img = getimagesize($_FILES['upload']['tmp_name']);
if(($infos_img[0] >= $Maxwidth) & ($infos_img[1] >= $Maxheight)) exit("Vous avez depasse la dimension maximum autorisee qui est 100*100 pixels <a href=index.html>[Charger une nouvelle image]</a>");
$ext = "";
if(array_key_exists($_FILES['upload']['type'],$ValidType)) $ext = $ValidType[$_FILES['upload']['type']];
if(empty($ext)) exit("Type de upload invalide <a href=index.html>[Charger une nouvelle image]</a>");
$liste = "abcdefghijklmnopqrstuvwxyz0123456789";
$NomImage = "";
while(strlen($NomImage) != 8) $NomImage .= $liste[rand(0,35)];
if(!move_uploaded_file($_FILES['upload']['tmp_name'], $dossier."/".$NomImage.".".$ext)) exit("l'upload a echoue <a href=index.html>[Charger une nouvelle image]</a>");
else
$image=$dossier."/".$NomImage.".".$ext;
{
echo "име : <strong>".$NomImage.".".$ext."</strong><br/>";
echo "размер : <strong>".$_FILES['upload']['size']." octets</strong><br/>";
echo "type : <strong>".$_FILES['upload']['type']."</strong><br/>";
echo "<b>http://serveur-perso.dyndns.org/tests/upload5/".$image."</b>";
echo "<b>[img]http://serveur-perso.dyndns.org/tests/upload5/".$image."[/img]</b>";
echo "<img src=\"$image\">";
}
?>
</center>
</body>
</html>
ии.. искам след като се ъплоудне картинката да се изпълнява този код (той да смалява ъплоуднатата картинка)..
Код:
<?php
// Parameters:
// src - path to source image
// dest - path to thumb (where to save it)
// x - max width
// y - max height
// q - quality (applicable only to JPG, 1 to 100, 100 - best)
// t - thumb type. "-1" - same as source, 1 = GIF, 2 = JPG, 3 = PNG
// f - save to file (1) or output to browser (0).
// Sample usage:
// 1. save thumb on server
// http://www.zubrag.com/thumb.php?src=test.jpg&dest=thumb.jpg&x=100&y=50
// 2. output thumb to browser
// http://www.zubrag.com/thumb.php?src=test.jpg&x=50&y=50&f=0
// Below are default values (if parameter is not passed)
// save to file (true) or output to browser (false)
$save_to_file = true;
// quality
$image_quality = 100;
// resulting image type (1 = GIF, 2 = JPG, 3 = PNG)
// enter code of the image type if you want override it
// or set it to -1 to determine automatically
$image_type = -1;
// maximum thumb side size
$max_x = 100;
$max_y = 100;
///////////////////////////////////////////////////
/////////////// DO NOT EDIT BELOW
///////////////////////////////////////////////////
$to_name = '';
if (isset($_REQUEST['f'])) {
$save_to_file = intval($_REQUEST['f']) == 1;
}
if (isset($_REQUEST['src'])) {
$from_name = $_REQUEST['src'];
}
else {
die("Source file name must be specified.");
}
if (isset($_REQUEST['dest'])) {
$to_name = $_REQUEST['dest'];
}
else if ($save_to_file) {
die("Thumbnail file name must be specified.");
}
if (isset($_REQUEST['q'])) {
$image_quality = intval($_REQUEST['q']);
}
if (isset($_REQUEST['t'])) {
$image_type = intval($_REQUEST['t']);
}
if (isset($_REQUEST['x'])) {
$max_x = intval($_REQUEST['x']);
}
if (isset($_REQUEST['y'])) {
$max_y = intval($_REQUEST['y']);
}
function SaveImage($type, $im, $filename, $quality, $to_file = true) {
$res = null;
// ImageGIF is not included into some GD2 releases, so it might not work
// output png if gifs are not supported
if(!function_exists('imagegif')) $type = 3;
switch ($type) {
case 1:
if ($to_file) {
$res = ImageGIF($im,$filename);
}
else {
header("Content-type: image/gif");
$res = ImageGIF($im);
}
break;
case 2:
if ($to_file) {
$res = ImageJPEG($im,$filename,$quality);
}
else {
header("Content-type: image/jpeg");
$res = ImageJPEG($im,'',$quality);
}
break;
case 3:
if ($to_file) {
$res = ImagePNG($im,$filename);
}
else {
header("Content-type: image/png");
$res = ImagePNG($im,'',$quality);
}
break;
}
return $res;
}
function ImageCreateFromType($type,$filename) {
$im = null;
switch ($type) {
case 1:
$im = ImageCreateFromGif($filename);
break;
case 2:
$im = ImageCreateFromJpeg($filename);
break;
case 3:
$im = ImageCreateFromPNG($filename);
break;
}
return $im;
}
// generate thumb from image and save it
function GenerateThumbFile($from_name, $to_name, $max_x, $max_y) {
global $save_to_file, $image_type, $image_quality;
// get source image size (width/height/type)
// orig_img_type 1 = GIF, 2 = JPG, 3 = PNG
list($orig_x, $orig_y, $orig_img_type, $img_sizes) = GetImageSize($from_name);
// should we override thumb image type?
$image_type = ($image_type != -1 ? $image_type : $orig_img_type);
// check for allowed image types
if ($orig_img_type < 1 or $orig_img_type > 3) die("Image type not supported");
if ($orig_x > $max_x or $orig_y > $max_y) {
// resize
$per_x = $orig_x / $max_x;
$per_y = $orig_y / $max_y;
if ($per_y > $per_x) {
$max_x = $orig_x / $per_y;
}
else {
$max_y = $orig_y / $per_x;
}
}
else {
// keep original sizes, i.e. just copy
if ($save_to_file) {
@copy($from_name, $to_name);
}
else {
switch ($image_type) {
case 1:
header("Content-type: image/gif");
include($from_name);
break;
case 2:
header("Content-type: image/jpeg");
include($from_name);
break;
case 3:
header("Content-type: image/png");
include($from_name);
break;
}
}
return;
}
if ($image_type == 1) {
// should use this function for gifs (gifs are palette images)
$ni = imagecreate($max_x, $max_y);
}
else {
// Create a new true color image
$ni = ImageCreateTrueColor($max_x,$max_y);
}
// Fill image with white background (255,255,255)
$white = imagecolorallocate($ni, 255, 255, 255);
imagefilledrectangle( $ni, 0, 0, $max_x, $max_y, $white);
// Create a new image from source file
$im = ImageCreateFromType($orig_img_type,$from_name);
// Copy the palette from one image to another
imagepalettecopy($ni,$im);
// Copy and resize part of an image with resampling
imagecopyresampled(
$ni, $im, // destination, source
0, 0, 0, 0, // dstX, dstY, srcX, srcY
$max_x, $max_y, // dstW, dstH
$orig_x, $orig_y); // srcW, srcH
// save thumb file
SaveImage($image_type, $ni, $to_name, $image_quality, $save_to_file);
}
// generate
GenerateThumbFile($from_name, $to_name, $max_x, $max_y);
?>
мн. ще съм ви благодарен ако ми кажете как ще стане :roll: :arrow: