Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

resize image

images php coding issues or problems here.

Moderators: macek, egami, gesf

resize image

Postby mm-marek » Sun Jul 10, 2005 10:09 am

Hi, i need resize image (not on the fly) on server. i want to upload image and then resize it
i have some scripts but problem is quality... can you help me?

i know how to upload, only resize. :help:
User avatar
mm-marek
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 10, 2005 10:02 am
Location: Praha Czech rep.

Postby Alexej Kubarev » Sun Jul 10, 2005 11:06 am

what script are you using?
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby mm-marek » Sun Jul 10, 2005 12:14 pm

i cant post a reply... i dont know why, maybe its too long, or scripts is forbidenn?
ok my reply is on my web:
http://www.marek-mixa.wz.cz/help.help

:help:
------------------------------------------------
The following is added by Alexei Kubarev
------------------------------------------------


i have one page: admin.php
i want to do all thinghs on this page. uploading text and images.

this script can upload file, but i want to resize it too. this is problem
red fragment as edit.php can resize, but when a make it together...



//RED: there i want upload and resize... (after send form)
<?
if ($akce == "Upload") {

if ($soubor_type == "text/plain" or $soubor_type="text/html") {
if (copy ($soubor, "$soubor_name")) {


//zmìna velikostí
// File and new size
$imgfile = '6.JPG';
$percent = 0.2;
header('Content-type: image/jpeg');

list($width, $height) = getimagesize($imgfile);
$newwidth = $width * $percent;
$newheight = $height * $percent;

$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);

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

imagejpeg($thumb);



//konec zmìny velikostí


Header("Location: //admin page");

}
else {
print "Pøi nahrávání souboru došlo k chybì!<BR>"; //error
}
}
else {
print "Soubor není požadového MIME typu!<BR>"; //error
}
}







BLUE: database for other things - forms (blog, results...)
if($ad):
$spoj = MySQL_PConnect ("", "" , "");
if (!$spoj):
echo "nepodaøilo se pøippojit k databázi<BR>";
else:

$dat = MySQL_Select_DB("");
if (!$dat):
echo "nepodaøilo se vybrat databázi<BR>";
else:



//sekce denik
if($blog==1):
$blog=0;
$denik = MySQL_Query("SELECT id FROM denik");
$pocet = MySQL_Num_Rows($denik);
$id= $pocet+1;
$denik = MySQL_Query("INSERT INTO denik VALUES ('$zprava','$datum','$nazev','$id')");
if (!$denik):
echo "nepodaøilo se zapsat do deníku<BR>";
else:
echo "zapsáno....<BR>";
Header("Location: //admin page");
endif;

//sekce výsledky
elseif ($result==1):
$result=0;
$denik = MySQL_Query("SELECT id FROM vysledky");
$pocet = MySQL_Num_Rows($denik);
$id= $pocet+1;
$denik = MySQL_Query("INSERT INTO vysledky VALUES ('$id','$poradi','$misto','$datum','$komentar')");
if (!$denik):
echo "nepodaøilo se zapsat do výsledkù<BR>"; //error
else:
echo "zapsáno....<BR>";
Header("Location: //admin page");
endif;

//sekce novinky
elseif ($news==1):
$news=0;
$novinky = MySQL_Query("SELECT id FROM novinky");
$pocet = MySQL_Num_Rows($novinky);
$id= $pocet+1;
$novinky = MySQL_Query("INSERT INTO novinky VALUES ('$id','$komentar')");
if (!$novinky):
echo "nepodaøilo se zapsat do novinek<BR>"; //error
else:
echo "zapsáno....<BR>"; //write
Header("Location: //admin page");
endif;

//konec sekcí
endif;
endif;
endif;
else:


//makes standart page (menu)
$fp = FOpen("head.php", "r");
FPassThru($fp);



//nulování formuláøových dat pro odeslání
$result=0;
$blog=0;
$news=0;

//enter admin page
if ($pass=="''):
?>
<FORM METHOD=POST id="adminform">
<INPUT TYPE=password NAME=pass VALUE=""><BR><BR>
<INPUT TYPE=Submit VALUE="Autorizuj">
</FORM>

<?

VIOLET: forms (uploading text and file)

elseif ($pass=='some password'):

if($zapis==news):
echo "Zapsáno do novinek";
elseif($zapis==blog):
echo "Zapsáno do deníku";
elseif($zapis==results):
echo "Zapsáno do výsledkù";
elseif($zapis==upload):
print "Soubor bajtù";

else:
echo "";
endif;
?>
<div style="float:left; position: relative; top:30px">
<B>Pøidání do deníku</B>
<PRE>

<FORM METHOD=POST >
<INPUT NAME=datum VALUE="<?echo $datum?>"><B> - Datum</B><BR>
<INPUT NAME=nazev VALUE="<?echo $nazev?>"><B> - Název</B><BR>
<BR><BR>
<TEXTAREA NAME=zprava COLS=30 ROWS=7 >
<?echo $zprava?>
</TEXTAREA><BR><BR>

<INPUT TYPE=Submit VALUE="Pøidání zprávy">
<INPUT TYPE=Reset VALUE="Smazání formuláøe">
<INPUT TYPE=HIDDEN NAME =ad VALUE=true>
<INPUT TYPE=HIDDEN NAME =blog VALUE="1">


</FORM>
</PRE>
<BR>
</div>
<div style="float:right; position: relative; top:30px">
<B>Pøidání do výsledkù</B>

<PRE>
<FORM METHOD=POST >
<INPUT NAME=datum VALUE="<?echo $datum?>"><B> - Datum</B><BR>
<INPUT NAME=misto VALUE="<?echo $misto?>"><B> - Název</B><BR>
<INPUT NAME=poradi VALUE="<?echo $poradi?>"><B> - poøadí</B><BR>


<TEXTAREA NAME=komentar COLS=25 ROWS=7 >
<?echo $komentar?>
</TEXTAREA><BR><BR>

<INPUT TYPE=Submit VALUE="Pøidání zprávy">
<INPUT TYPE=Reset VALUE="Smazání formuláøe">
<INPUT TYPE=HIDDEN NAME =ad VALUE=true>
<INPUT TYPE=HIDDEN NAME =result VALUE="1">


</FORM>
</PRE>
<BR>
</div>
<HR>

<div style="float:left; position: relative; top:30px">
<B>Pøidání do Novinek</B>
<PRE>

<FORM METHOD=POST >
<TEXTAREA NAME=komentar COLS=30 ROWS=7 >
<?echo $komentar?>
</TEXTAREA><BR><BR>

<INPUT TYPE=Submit VALUE="Pøidání zprávy">
<INPUT TYPE=Reset VALUE="Smazání formuláøe">
<INPUT TYPE=HIDDEN NAME =ad VALUE=true>
<INPUT TYPE=HIDDEN NAME =news VALUE="1">
</FORM>
</PRE>
<BR>
</div>
<div style="float:right; position: relative; top:30px">
<B>adresa fotky pro upload:</B>
<FORM METHOD="post" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="soubor" SIZE="20"><BR><BR>
<INPUT TYPE="submit" NAME="akce" VALUE="Upload">
</FORM>
</div>




<?
//bad password (firs form)
else:
echo "nepovolený pøístup";
endif;
//stadrad page
$fp = FOpen("tail.php", "r");
FPassThru($fp);
endif;
?>
User avatar
mm-marek
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 10, 2005 10:02 am
Location: Praha Czech rep.

Postby Alexej Kubarev » Sun Jul 10, 2005 2:12 pm

hmmz... i see you have been using a VB style coding...
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby mm-marek » Sun Jul 10, 2005 11:16 pm

??? visual basic? where?

but my firs language is VS...
User avatar
mm-marek
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 10, 2005 10:02 am
Location: Praha Czech rep.

Postby Alexej Kubarev » Mon Jul 11, 2005 2:16 am

i ment VB style... if-endif style is more VB style then common C-style

VS? VS stands for Visual Studio :P I think you ment VB as your first language.. that would explain your coding style :)

My prior to PHP language was C so i thought it was easier to code with C-style just like the most of us.. :)
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby mm-marek » Mon Jul 11, 2005 3:13 am

ok...
i think tahat if endif is easier than other...

but what about my problem? :help:
User avatar
mm-marek
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 10, 2005 10:02 am
Location: Praha Czech rep.

Postby Alexej Kubarev » Mon Jul 11, 2005 8:38 am

well, first of all: you are using the code for register_globals = on (Its BAD)

then the code is basicly good, however that code resizes and outputs the headers... is it what you want to do?
or you want to create a new image and store it on the server?
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby mm-marek » Mon Jul 11, 2005 9:06 am

hmm i want to upload file and when its uploaded, resize it.

in code i have $imgfile = '6.JPG'; (red area) but in i will change it for $imgfile=$soubor_name (file for resize is file which is uploaded)

much headers is there. I know it. When one fragment of script (upload file, upload text to database...) is finished, header will resstart the page. in location will be password for this page and this: - will be write whats hapened...

elseif ($pass=='some password'):

if($zapis==news):
echo "Zapsáno do novinek"; //writen to news
elseif($zapis==blog):
echo "Zapsáno do deníku"; //writen to blog
elseif($zapis==results):
echo "Zapsáno do výsledkù"; //writen to results
elseif($zapis==upload):
print "Soubor bajtù"; //upload succesfull

else:
echo ""; //first open of this page
endif;


i want to make a gallery of photos. i found some scripts on internet but almost its not fuction or its too dificult for me(with rotate and more...)
User avatar
mm-marek
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 10, 2005 10:02 am
Location: Praha Czech rep.

Postby Alexej Kubarev » Mon Jul 11, 2005 11:56 am

okey: take a look at php.net manual especially those image functions that you are using: they have a pretty good resampling code :) in the comments
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby mm-marek » Fri Jul 15, 2005 3:50 am

ok now its good....

Code: Select all
<?
session_start();
if ($akce == "Upload") {

  if ($soubor_type == "text/plain" or $soubor_type="text/html") {
   $soubor_name=StrToLower($soubor_name);
    if (copy ($soubor, "upload_foto/$soubor_name")) {
     
    
$imgfile = "upload_foto/".$soubor_name;
$percent = 0.9;


list($width, $height) = getimagesize($imgfile);
$newwidth = $width * $percent;
$newheight = $height * $percent;

$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);

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

imagejpeg($thumb,"upload_foto/small_".$soubor_name);


session_register("soubor_name");
session_register("soubor_size");


problem was in imagejpeg($thumb,"upload_foto/small_".$soubor_name); forgotten path to file!
User avatar
mm-marek
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 10, 2005 10:02 am
Location: Praha Czech rep.


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron