Ja jesam

Ovo su f-je koje sam pravio pre xy-god. koje upravo rade resize & crop. Ali avaj, ja ne znam to da implementiram u SMF.
Odavno se ne bavim PHP-om, ali eto da se zna da i to moze

<?php
//dozvoljavamo samo jpg format
//kad budem uradio des za pop-up reci cu ti dimenzije
//ovo je neka opsta provera
$max_velicina_filea = 204800; //u bitovima
$max=$max_velicina_filea/1024;
//$_FILES['plan'] je file uploadovan sa form polja cije je ime 'plan'
$plan_temp = $_FILES['plan']['tmp_name'];
$plan_name = $_FILES['plan']['name'];
$plan_type = $_FILES['plan']['type'];
$plan_velicina = $_FILES['plan']['size'];
//ovde moras da proveris kako ie a kako ff vide jpg
$dozvoljeni_tpovi = array ('application/msword','application/vnd.ms-excel','text/richtext','text/plain','application/vnd.ms-powerpoint','application/x-zip-compressed','application/octet-stream','application/pdf');
//da li upste imamo file
if ($plan_temp == "none") {
echo $greska;
echo '<p align="center" class="upozorenja" >error. </p>';
}
// da li je tip dozvoljen
else if (!in_array ($plan_type, $dozvoljeni_tpovi)) {
echo $greska;
echo '<p align="center" class="upozorenja" >????? ????? ???? ??? ???????? ???? ????????? ?? upload</p>';
korak_nazad();
}
//da li je velicina dozvoljena
else if ($plan_velicina>$max_velicina_filea) {
echo $greska;
echo '<p align="center" class="upozorenja" >???????? ????? ???? ??? ???????? ?? ???? ?? ?????????</p>';
korak_nazad();
}
//funkcije za upload i obradu slike
function proveri_extenziju ($ime_datoteke){
$dozvoljeni_tipovi = array ('doc','xls','pps','ppt','zip','pdf');
$tmp_ime = explode(".", $ime_datoteke);
$duzina_niza = count($tmp_ime);
$ime_za_provery = $tmp_ime[$duzina_niza-1];
if (in_array($ime_za_provery, $dozvoljeni_tipovi)){
$retval = true;
}else{
$retval = false;
}
return $retval;
}
function procisti_ime ($imefx) {
//Jos malo bezbednosti - da ime bude bezbedno i da ne jebava server
$imefx = strtolower($imefx);
$imefx = strip_tags($imefx);
$imefx = escapeshellcmd($imefx);
//Define array with unwanted characters in the filename and replacement
$array_with_replace_characters = array(
"&" =>"_",
" " =>"_",
"\t" =>"_",
"\n" =>"_",
"?" =>"_",
">" =>"_",
"<" =>"_",
"+" =>"_",
"~" =>"_",
"'" =>"_",
"\\" =>"_",
"\"" =>"_",
";" =>"_",
":" =>"_",
"{" =>"_",
"}" =>"_",
"[" =>"_",
"]" =>"_",
"," =>"_",
"%" =>"_",
"#" =>"_",
"@" =>"_",
"*" =>"_",
"^" =>"_",
"\u0020" =>"_",
"/" =>"_",
"©" =>"_");
$imefx = strtr($imefx, $array_with_replace_characters);
$imefx = trim($imefx);
return $imefx;
}
//ovu f-ju sam sad napisao i nisam je probao da li radi pa stoga i ne garantujem za njenu ispravnost
function JedinstvenoIme ($filename, $dirpath){
$new_filename = procisti_ime ($filename);
$target_staza = $dirpath;
$check_dirpath = $dirpath.$new_filename;
$i=1;
$test="OFF";
while($test=="OFF"){
if(@file_exists($check_dirpath)){
$new_filename=$i."_".$new_filename;
$check_dirpath = $dirpath.$new_filename;
$i++;
} else { $test="ON"; }
}
return $new_filename;
}
//f-je za resize slika
//f-ja koja razresava po kojoj stranici treba resizovati image
//$fw - zeljena sirina, $fh - zeljena visina, $im_w - image_width, $im_h image height
//poziva se u ResizeImageJpg f-ji
function ResizeProportional($fw, $fh, $im_w, $im_h){
$new_im_w;
$new_im_h;
$retval = Array();
$new_im_h = $fh;
$new_im_w = ($im_w * $new_im_h) / $im_h;
if ($new_im_w < $fw){
//must resize img by width
$new_im_w = $fw;
$new_im_h = ($im_h * $new_im_w) / $im_w;
}
$retval[0] = $new_im_w;
$retval[1] = $new_im_h;
return $retval;
}
//resizuje img onako kako ja hocu
//prvo proporcionalno smanji ili poveca img tako da jednu od stranica dovede na zeljenu velicinu
//i to onu stranicu koja je bliza zeljenoj velicini a zatim odsece visak
function ResizeImageJpg( $forcedwidth, $forcedheight, $sourcefile){
$fw = $forcedwidth;
$fh = $forcedheight;
$is = getimagesize( $sourcefile );//$is[0] width , $is[1] height
$is_w = $is[0];
$is_h = $is[1];
//image is corect sizes
if ($fw == $is[0] && $fh == $is[1]) return;
$newSizes = ResizeProportional($fw, $fh, $is_w, $is_h);
$img_src = imagecreatefromjpeg( $sourcefile );//returns an image identifier representing the image obtained from the given filename
$img_dst = imagecreatetruecolor( $newSizes[0], $newSizes[1] );//creates new black truecolor image
imagecopyresized($img_dst,$img_src, 0, 0, 0, 0, $newSizes[0], $newSizes[1], $is_w, $is_h);
$img_final = imagecreatetruecolor( $fw, $fh );//creates new black truecolor image
imagecopy($img_final,$img_dst, 0, 0, 0, 0, $fw, $fh);
//imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );//copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.
if( !imagejpeg( $img_final, $sourcefile, 100 ) )//creates a JPEG file from the given image . (image, filename, quality )
{
exit();
}
}
//pravi tumb od slike
function CreateTumb($fw, $fh, $sourcefile, $destfile){
$is = getimagesize( $sourcefile );//$is[0] width , $is[1] height
$is_w = $is[0];
$is_h = $is[1];
$img_src = imagecreatefromjpeg( $sourcefile );//returns an image identifier representing the image obtained from the given filename
$img_dst = imagecreatetruecolor( $fw, $fh );//creates new black truecolor image
imagecopyresized($img_dst,$img_src, 0, 0, 0, 0, $fw, $fh, $is_w, $is_h);
if( !imagejpeg( $img_dst, $destfile, 80 ) )//creates a JPEG file from the given image . (image, filename, quality )
{
exit();
}
}
//f-ja koju sam skinuo sa neta koja je dobra ali nije radila zeljeni posao pa sam od nje napravio gornje f-je.
function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile ){
$fw = $forcedwidth;
$fh = $forcedheight;
$is = getimagesize( $sourcefile );//$is[0] width , $is[1] height
if( $is[0] >= $is[1] ){
//orentation lendscape
$orientation = 0;
}
else{
//orentation portret
$orientation = 1;
$fw = $forcedheight;
$fh = $forcedwidth;
}
if ( $is[0] > $fw || $is[1] > $fh )
{
if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) )
{
$iw = $fw;
$ih = ( $fw / $is[0] ) * $is[1];
}
else
{
$ih = $fh;
$iw = ( $ih / $is[1] ) * $is[0];
}
$t = 1;
}
else
{
$iw = $is[0];
$ih = $is[1];
$t = 2;
}
if ( $t == 1 )
{
$img_src = imagecreatefromjpeg( $sourcefile );//returns an image identifier representing the image obtained from the given filename
$img_dst = imagecreatetruecolor( $iw, $ih );//creates new black truecolor image
imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );//copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.
if( !imagejpeg( $img_dst, $destfile, 90 ) )//creates a JPEG file from the given image . (image, filename, quality )
{
exit();
}
}
else if ( $t == 2 )
{
copy( $sourcefile, $destfile );
}
}
?>