", $stringi); return ($stringi); } function tags_to_html($text_to_change) { $text_to_change = preg_replace("#\r\n#","\n", $text_to_change); $text_to_change = preg_replace("#\n\r#","\n", $text_to_change); $text_to_change = preg_replace("#\n#","
", $text_to_change); $text_to_change = preg_replace('#//b#','', $text_to_change); $text_to_change = preg_replace('#b//#','', $text_to_change); $text_to_change = preg_replace('#//i#','', $text_to_change); $text_to_change = preg_replace('#i//#','', $text_to_change); $text_to_change = preg_replace('#//u#','', $text_to_change); $text_to_change = preg_replace('#u//#','', $text_to_change); $text_to_change = preg_replace('#//B#','', $text_to_change); $text_to_change = preg_replace('#B//#','', $text_to_change); $text_to_change = preg_replace('#//I#','', $text_to_change); $text_to_change = preg_replace('#I//#','', $text_to_change); $text_to_change = preg_replace('#//U#','', $text_to_change); $text_to_change = preg_replace('#U//#','', $text_to_change); return $text_to_change; } function lf_to_br($text_to_change) { $text_to_change = preg_replace("#\r\n#","\n", $text_to_change); $text_to_change = preg_replace("#\n\r#","\n", $text_to_change); $text_to_change = preg_replace("#\n#","
", $text_to_change); return $text_to_change; } /* ------------------------------------------------------------- KUVAFUNKTIOT ----------------------------------------------------------------------- */ // memorylimitin saato function adjust_memory($from_file) { $imageInfo = getimagesize($from_file); $MB = pow(1024,2); // number of bytes in 1M $K64 = pow(2,16); // number of bytes in 64K $TWEAKFACTOR = 2; // Or whatever works for you $memoryNeeded = round( ( $imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + $K64 ) * $TWEAKFACTOR ); $memoryHave = memory_get_usage(); $memoryLimitMB = (integer) ini_get('memory_limit'); $memoryLimit = $memoryLimitMB * $MB; if ( function_exists('memory_get_usage') && $memoryHave + $memoryNeeded > $memoryLimit ) { $newLimit = $memoryLimitMB + ceil( ( $memoryHave + $memoryNeeded - $memoryLimit ) / $MB ); ini_set( 'memory_limit', $newLimit . 'M' ); } } // harmaasavy function create_grey_img($from_file,$to_file,$quality=90) { $bild = imagecreatefromjpeg($from_file); $x = imagesx($bild); $y = imagesy($bild); for($i=0; $i<$y; $i++) { for($j=0; $j<$x; $j++) { $pos = imagecolorat($bild, $j, $i); $f = imagecolorsforindex($bild, $pos); $gst = $f["red"]*0.15 + $f["green"]*0.5 + $f["blue"]*0.35; $col = imagecolorresolve($bild, $gst, $gst, $gst); imagesetpixel($bild, $j, $i, $col); } } imagejpeg($bild,$to_file,$quality); imagedestroy($bild); } // skaalaa prosentteina function resize_img_percent($from_file, $to_file, $percent, $quality=90) { resize_img($from_file,$to_file,$quality,false,false,$percent); } // skaalaa laatikkoon function resize_img_fit_to($from_file, $to_file, $width=false, $height=false, $quality=90) { resize_img($from_file,$to_file,$quality,$width,$height,false); } // rajaa laatikkoon function resize_and_crop_img($from_file, $to_file, $new_width, $new_height, $quality=90){ $size = getimagesize($from_file); $w = $size[0]; $h = $size[1]; if( $simg = ImageCreateFromJPEG($from_file) ){ // Read JPEG Image $make_type='jpg'; }elseif( $simg = ImageCreateFromPNG($from_file) ){ // Read JPEG Image $make_type='png'; }elseif( $simg = ImageCreateFromGIF($from_file) ){ // Read JPEG Image $make_type='png'; }else{ $simg = false; // If image is not JPEG, PNG, or GIF } if($simg!==false){ $dimg = imagecreatetruecolor($new_width, $new_height); if($make_type=='png'){ ImageAlphaBlending($dimg, false); $taustavari = imagecolorallocatealpha($dimg, 255, 255, 255, 127); imagefilledrectangle($dimg, 0, 0, $new_width, $new_height, $taustavari); } $wm = $w/$new_width; $hm = $h/$new_height; $h_height = $new_height/2; $w_height = $new_width/2; if($w> $h) { $adjusted_width = $w / $hm; $half_width = $adjusted_width / 2; $int_width = $half_width - $w_height; imagecopyresampled( $dimg, $simg, -$int_width, 0, 0, 0, $adjusted_width, $new_height, $w, $h ); } elseif(($w <$h) || ($w == $h)) { $adjusted_height = $h / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled( $dimg, $simg, 0, -$int_height, 0, 0, $new_width, $adjusted_height, $w, $h ); } else { imagecopyresampled( $dimg, $simg, 0, 0, 0, 0, $new_width, $new_height, $w, $h ); } if($make_type=='jpg'){ imagejpeg ( $dimg, $to_file, $quality ); }elseif($make_type=='png'){ if($quality>9){ $quality = round($quality/10); } $to_file = str_ireplace('.gif','.png', $to_file); imageSaveAlpha($thumb, true); imagepng ( $dimg, $to_file, $quality, PNG_ALL_FILTERS ); } } } // skaalaa mittoihin function resize_img($from_file, $to_file, $quality=90, $width=false, $height=false, $percent=false) { $img = $from_file; if($height!==false){$h=$height;} if($width!==false){$w=$width;} // - get image size of img $x = getimagesize($img); $sw = $x[0]; $sh = $x[1]; if(isset ($w) AND isset ($h)){ if($sw>$w || $sh>$h){ $constrain=true; } } if ($percent > 0) { // calculate resized height and width if percent is defined $percent = $percent * 0.01; $w = $sw * $percent; $h = $sh * $percent; } else { if (isset ($w) AND !isset ($h)) { // autocompute height if only width is set $h = (100 / ($sw / $w)) * .01; $h = round ($sh * $h); } elseif (isset ($h) AND !isset ($w)) { // autocompute width if only height is set $w = (100 / ($sh / $h)) * .01; $w = round ($sw * $w); } elseif (isset ($h) AND isset ($w) AND isset ($constrain)) { // get the smaller resulting image dimension if both height // and width are set and $constrain is also set $hx = (100 / ($sw / $w)) * .01; $hx = round ($sh * $hx); $wx = (100 / ($sh / $h)) * .01; $wx = round ($sw * $wx); if ($hx < $h) { $h = (100 / ($sw / $w)) * .01; $h = round ($sh * $h); } else { $w = (100 / ($sh / $h)) * .01; $w = round ($sw * $w); } } } if( $im = ImageCreateFromJPEG($img) ){ // Read JPEG Image $make_type='jpg'; }elseif( $im = ImageCreateFromPNG($img) ){ // Read JPEG Image $make_type='png'; }elseif( $im = ImageCreateFromGIF($img) ){ // Read JPEG Image $make_type='png'; }else{ $im = false; // If image is not JPEG, PNG, or GIF } if (!$im) { // We get errors from PHP's ImageCreate functions... // So let's echo back the contents of the actual image. //readfile ($img); } else { // Create the resized image destination $thumb = ImageCreateTrueColor ($w, $h); if($make_type=='png'){ ImageAlphaBlending($thumb, false); $taustavari = imagecolorallocatealpha($thumb, 255, 255, 255, 127); imagefilledrectangle($thumb, 0, 0, $w, $h, $taustavari); } // - Copy from image source, resize it, and paste to image destination ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh); // - Output resized image if($make_type=='jpg'){ imagejpeg ( $thumb, $to_file, $quality ); }elseif($make_type=='png'){ if($quality>9){ $quality = round($quality/10); } $to_file = str_ireplace('.gif','.png', $to_file); imageSaveAlpha($thumb, true); //imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] ) imagepng ( $thumb, $to_file, $quality, PNG_ALL_FILTERS ); } } } function resize_img2($from_file, $to_file, $width, $height, $pictype = "", $quality=90) //function resize_img($filename, $dest, $width, $height, $pictype = "", $quality=90) { $format = strtolower(substr(strrchr($from_file,"."),1)); switch($format) { case 'gif' : $type ="gif"; $img = imagecreatefromgif($from_file); break; case 'png' : $type ="png"; $img = imagecreatefrompng($from_file); break; case 'jpg' : $type ="jpg"; $img = imagecreatefromjpeg($from_file); break; case 'jpeg' : $type ="jpg"; $img = imagecreatefromjpeg($from_file); break; default : die ("ERROR; UNSUPPORTED IMAGE TYPE"); break; } list($org_width, $org_height) = getimagesize($from_file); $xoffset = 0; $yoffset = 0; if ($pictype == "thumb") // To minimize destortion { if ($org_width / $width > $org_height/ $height) { $xtmp = $org_width; $xratio = 1-((($org_width/$org_height)-($width/$height))/2); $org_width = $org_width * $xratio; $xoffset = ($xtmp - $org_width)/2; } elseif ($org_height/ $height > $org_width / $width) { $ytmp = $org_height; $yratio = 1-((($width/$height)-($org_width/$org_height))/2); $org_height = $org_height * $yratio; $yoffset = ($ytmp - $org_height)/2; } //Added this else part ------------- } else { $xtmp = $org_width/$width; $new_width = $width; $new_height = $org_height/$xtmp; if ($new_height > $height){ $ytmp = $org_height/$height; $new_height = $height; $new_width = $org_width/$ytmp; } $width = round($new_width); $height = round($new_height); } $img_n=imagecreatetruecolor ($width, $height); imagecopyresampled($img_n, $img, 0, 0, $xoffset, $yoffset, $width, $height, $org_width, $org_height); if($type=="gif") { imagegif($img_n, $to_file); } elseif($type=="jpg") { imagejpeg($img_n, $to_file,$quality); } elseif($type=="png") { imagepng($img_n, $to_file); } elseif($type=="bmp") { imagewbmp($img_n, $to_file); } imagedestroy($img); imagedestroy($img_n); Return true; } ?>