Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / var / www / html / sman1baleendah_sch_id-1111111111111 / functions / | server ip : 104.21.89.46 your ip : 172.69.214.34 H O M E |
Filename | /var/www/html/sman1baleendah_sch_id-1111111111111/functions/fungsi_crop.php |
Size | 3.34 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 06-May-2025 08:13 |
Last modified | 05-May-2025 16:21 |
Last accessed | 05-Jul-2025 11:27 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
// sumber ilmu website com
function cropImage($nw, $nh, $source, $stype, $dest) {
$size = getimagesize($source); // ukuran gambar
$w = $size[0];
$h = $size[1];
switch($stype) { // format gambar
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh); // menciptakan image baru
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/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,$nh,$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,$nw,$adjusted_height,$w,$h);
}
else {
imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
function potongimageprofil($source, $stype, $dest,$nw,$nh, $x1,$y1) {
//$w = $asli_w;
//$h = $asli_h;
switch($stype) { // format gambar
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh); // menciptakan image baru
imagecopyresampled($dimg,$simg,0,0,$x1,$y1,$nw,$nh,$nw,$nh);
imagejpeg($dimg,$dest,100);
}
function crop_image($src, $dest = "", $width = 0, $height = 0, $valign = "") {
if(!file_exists($src)) {
return false;
}
if(!in_array(array_pop(explode(".", strtolower($src))), array("jpg", "png", "gif"))) {
return false;
}
if(!in_array(array_pop(explode(".", strtolower($dest))), array("jpg", "png", "gif")) & !empty($dest)) {
return false;
}
$y = 0;
if(!in_array($valign, array("top", "middle", "bottom")) || empty($valign)) {
$valign = "top";
}
$fp = fopen($src, "rb");
$data = fread($fp, filesize($src) + 1);
fclose($fp);
$tmp = imagecreatefromstring($data);
$w = imagesx($tmp);
$h = imagesy($tmp);
$wd = $width;
$hd = $height;
$width = !empty($width) ? $width : $w;
$height = !empty($height) ? $height : $h;
if($wd > 0 && $w <> $width) {
$height = round(($h * $width) / $w);
if($hd > 0 && $height > $hd) {
$hs = $h;
$height = $hd;
$h = round(($hd * $w) / $width);
switch($valign) {
case "top" : $y = 0; break;
case "middle" : $y = round(($hs - $h) / 2); break;
case "bottom" : $y = $hs - $h; break;
}
}
}
if($hd > 0 && $h <> $height) {
$width = round(($w * $height) / $h);
if($wd > 0 && $witdh > $wd) {
$width = $wd;
$w = round(($wd * $h) / $height);
}
}
$im = imagecreatetruecolor($width, $height);
imagecopyresized($im, $tmp, 0, 0, 0, $y, $width, $height, $w, $h);
switch(array_pop(explode(".", strtolower($dest)))) {
case "png" :
if(empty($dest)) { header("Content-Type: image/png"); }
@imagepng($im, !empty($dest) ? $dest : null);
break;
case "gif" :
if(empty($dest)) { header("Content-Type: image/gif"); }
@imagegif($im, !empty($dest) ? $dest : null);
break;
default :
if(empty($dest)) { header("Content-Type: image/jpeg");}
@imagejpeg($im, !empty($dest) ? $dest : null);
break;
}
}
?>
// sumber ilmu website com
function cropImage($nw, $nh, $source, $stype, $dest) {
$size = getimagesize($source); // ukuran gambar
$w = $size[0];
$h = $size[1];
switch($stype) { // format gambar
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh); // menciptakan image baru
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/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,$nh,$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,$nw,$adjusted_height,$w,$h);
}
else {
imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
function potongimageprofil($source, $stype, $dest,$nw,$nh, $x1,$y1) {
//$w = $asli_w;
//$h = $asli_h;
switch($stype) { // format gambar
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh); // menciptakan image baru
imagecopyresampled($dimg,$simg,0,0,$x1,$y1,$nw,$nh,$nw,$nh);
imagejpeg($dimg,$dest,100);
}
function crop_image($src, $dest = "", $width = 0, $height = 0, $valign = "") {
if(!file_exists($src)) {
return false;
}
if(!in_array(array_pop(explode(".", strtolower($src))), array("jpg", "png", "gif"))) {
return false;
}
if(!in_array(array_pop(explode(".", strtolower($dest))), array("jpg", "png", "gif")) & !empty($dest)) {
return false;
}
$y = 0;
if(!in_array($valign, array("top", "middle", "bottom")) || empty($valign)) {
$valign = "top";
}
$fp = fopen($src, "rb");
$data = fread($fp, filesize($src) + 1);
fclose($fp);
$tmp = imagecreatefromstring($data);
$w = imagesx($tmp);
$h = imagesy($tmp);
$wd = $width;
$hd = $height;
$width = !empty($width) ? $width : $w;
$height = !empty($height) ? $height : $h;
if($wd > 0 && $w <> $width) {
$height = round(($h * $width) / $w);
if($hd > 0 && $height > $hd) {
$hs = $h;
$height = $hd;
$h = round(($hd * $w) / $width);
switch($valign) {
case "top" : $y = 0; break;
case "middle" : $y = round(($hs - $h) / 2); break;
case "bottom" : $y = $hs - $h; break;
}
}
}
if($hd > 0 && $h <> $height) {
$width = round(($w * $height) / $h);
if($wd > 0 && $witdh > $wd) {
$width = $wd;
$w = round(($wd * $h) / $height);
}
}
$im = imagecreatetruecolor($width, $height);
imagecopyresized($im, $tmp, 0, 0, 0, $y, $width, $height, $w, $h);
switch(array_pop(explode(".", strtolower($dest)))) {
case "png" :
if(empty($dest)) { header("Content-Type: image/png"); }
@imagepng($im, !empty($dest) ? $dest : null);
break;
case "gif" :
if(empty($dest)) { header("Content-Type: image/gif"); }
@imagegif($im, !empty($dest) ? $dest : null);
break;
default :
if(empty($dest)) { header("Content-Type: image/jpeg");}
@imagejpeg($im, !empty($dest) ? $dest : null);
break;
}
}
?>