ДТ РАБОТИЛНИЦА

Регистрирайте безплатен акаунт днес, за да станете член! След като влезете, ще можете да участвате в този сайт, като добавяте свои собствени теми и публикации, както и да се свързвате с други членове чрез вашата лична пощенска кутия!

  • Здравейте, майстори на заваряването, кодирането и автомобилните технологии!

    Аз съм Тони Ангелчовски, създател на dtgarage.eu - вашата нова дигитална работилница. С визията за място, където можем да обменяме идеи, да се обучаваме и да растем заедно, dtgarage.eu събира любители и професионалисти от света на заваряването, автомобилите, IT и уеб кодирането.

    В dtgarage.eu, ние сме общност, която е готова да помага и подкрепя всеки свой член. Ние вярваме, че всеки от нас може да допринесе за развитието на тази платформа, независимо дали е професионалист или ентусиаст.

    Само една стъпка ви дели от това да станете част от нашата общност - регистрацията. Регистрирайте се сега и открийте света на dtgarage.eu - мястото, където можем да създаваме и растем заедно.

    Приключението започва тук. Добре дошли в DTGARAGE.EU!

php PHP скрипт за оразмеряване на снимка

toni

Administrator
Staff member
Случвало ли ви е се бързо да оразмерите снимка? Сега ще ви покажа един PHP скрипт за бързо оразмеряване на снимка.
Писал съм го преди 10-15 години
PHP Код:
PHP:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if($_FILES['image']) {
preg_match('/\.([A-Za-z]+?)$/', $_FILES['image']['name'], $matches);
$matches[1] = strtolower($matches[1]);
if($matches[1] == 'png' && function_exists('imagecreatefrompng') || $matches[1]
== 'jpg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'jpeg' &&
function_exists('imagecreatefromjpeg') || $matches[1] == 'gif' && function_exists('imagecreatefromgif')  || $matches[1] == 'bmp' && function_exists('imagecreatefromwbmp')) {
list($owidth, $oheight) = getimagesize($_FILES['image']['tmp_name']);
if($_POST['resizeby'] == 'height') {
$nheight = ($_POST['size']>1)?$_POST['size']:600;
$nwidth = $nheight / $oheight * $owidth;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
else {
$nwidth = ($_POST['size']>1)?$_POST['size']:800;
$nheight = $nwidth / $owidth * $oheight;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
if($matches[1] == 'png')
$original = imagecreatefrompng($_FILES['image']['tmp_name']);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
$original = imagecreatefromjpeg($_FILES['image']['tmp_name']);
if($matches[1] == 'gif')
$original = imagecreatefromgif($_FILES['image']['tmp_name']);
if($matches[1] == 'bmp')
$original = imagecreatefromwbmp($_FILES['image']['tmp_name']);
imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);
header('Content-Disposition: attachment; filename="'.$_FILES['image']['name'].'"');
header('Content-type: image/'.(($matches[1] == 'jpg')?'jpeg':$matches[1]));
if($matches[1] == 'png')
imagepng($resized);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
imagejpeg($resized);
if($matches[1] == 'gif')
imagegif($resized);
if($matches[1] == 'bmpg')
imagewbmp($resized);
exit();
} else
$error = 'File type not supported!';
} else
$error = 'No image uploaded!';
}
?><?php print '<'.'?xml version="1.0" encoding="windows-1251"?'.'>'; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" ><head><title>Resize Image</title><link rel="stylesheet" href="resize.css" type="text/css" /></head><body><h1>Resize Image</h1><?php
if($error)
print '<p>'.$error.'</p>';
?><form action="" method="post" enctype="multipart/form-data" ><p>Upload your JPG, JPEG, GIF, PNG or BMP image: <br /><input type="file" name="image" /></p><p>Choose a height or width you want your image to be: <br /><select name="resizeby"><option value="width" selected="true">Width:</option><option value="height">Height:</option></select><input type="text" name="size" id="size" value="800" /> pixels</p><p><input type="submit" value="Submit" id="submit" /></p></form><p id="footer"><!--You may not remove the following line without permission!-->Powered by <a href="http://angelchovski.com/">Toni Angelchovski</a>.
</p></body></html>
Ще сложим и малко стил за по-добър изглед.
CSS Код:
CSS:
html {
text-align: center;
background-color: #373737;
}body {
padding: 5px 5px 5px 5px;
width: 500px;
height: 300px;
background-color: #BFBFBF;
border: 10px solid #000;
margin: 0 auto;
text-align: left;
position: absolute;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -250px;
font-family: sans-serif;
font-size: 15px;
background-image: url(toni.png);
background-repeat: no-repeat;
background-position: bottom right;
}
input {
font-size: 15px;
}
h1, iframe {
padding: 0;
margin: 0;
}
#size {
width: 4em;
}
#submit {
font-size: 20px;
background-color: #00b2ff;
color: #FFF;
border: 3px solid #000;
}
#footer {
text-align: center;
font-size: small;
}

Автор: Тони Ангелчовски
 
Last edited:
Здравейте , в старият форум имаше и демо на проектите. Дали пак ще има тази екстра?
 
Пробвах скрипта и работи чудесно, мисля да му направя нови дрешки HTML2 CSS3 …:cool:.
 
Resize Image.png

Ето код за новата дрешка:

CSS:
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');

html {
  text-align: center;
  background-color: #1c1c1c;
}

body {
  padding: 15px;
  width: 600px;
  height: 350px;
  background-color: #2f2f2f;
  border: 10px solid #555;
  margin: 0 auto;
  text-align: left;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -175px;
  margin-left: -300px;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  color: #f0f0f0; /* Светъл цвят на текста */
  border-radius: 10px;
  box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.6);
}

input {
  font-size: 15px;
  color: #333; /* Тъмен цвят на текста в полето за въвеждане */
}

h1, iframe {
  padding: 0;
  margin: 0;
  color: #f0f0f0; /* Светъл цвят на заглавието */
}

#size {
  width: 4em;
  border-radius: 4px;
  box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.6);
}

#submit {
  font-size: 20px;
  background-color: #0076ff;
  color: #FFF;
  border: 3px solid #000;
  border-radius: 6px;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.6);
}

#footer {
  text-align: center;
  font-size: small;
  color: #ccc;
}

/* Нови стилове за линка */
#footer a {
  color: #60aaff;
  text-decoration: none;
  font-weight: 700;
  transition: color 0.3s;
}

#footer a:hover {
  color: #89c5ff;
}
 
View attachment 893

Ето код за новата дрешка:

CSS:
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');

html {
  text-align: center;
  background-color: #1c1c1c;
}

body {
  padding: 15px;
  width: 600px;
  height: 350px;
  background-color: #2f2f2f;
  border: 10px solid #555;
  margin: 0 auto;
  text-align: left;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -175px;
  margin-left: -300px;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  color: #f0f0f0; /* Светъл цвят на текста */
  border-radius: 10px;
  box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.6);
}

input {
  font-size: 15px;
  color: #333; /* Тъмен цвят на текста в полето за въвеждане */
}

h1, iframe {
  padding: 0;
  margin: 0;
  color: #f0f0f0; /* Светъл цвят на заглавието */
}

#size {
  width: 4em;
  border-radius: 4px;
  box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.6);
}

#submit {
  font-size: 20px;
  background-color: #0076ff;
  color: #FFF;
  border: 3px solid #000;
  border-radius: 6px;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.6);
}

#footer {
  text-align: center;
  font-size: small;
  color: #ccc;
}

/* Нови стилове за линка */
#footer a {
  color: #60aaff;
  text-decoration: none;
  font-weight: 700;
  transition: color 0.3s;
}

#footer a:hover {
  color: #89c5ff;
}
Изпревари ме :p
 
Top Bottom