How to crop images?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
btrade
User
Posts: 357

How to crop images?

Post by btrade »

How can to make CROP images?
Proportions is defect w & h.
Where may I look example?


btrade
User
Posts: 357

Post by btrade »

I try to use this solution http://www.hkvforums.com/viewtopic.php? ... hilit=crop
But I don't understand how used is this


btrade
User
Posts: 357

Post by btrade »

Yes, my the work solution

  1. Insert the functons in Global Code

// -------------- RESIZE FUNCTION -------------
// Function for resizing any jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png"){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
if ($ext == "gif"){
imagegif($tci, $newcopy);
} else if($ext =="png"){
imagepng($tci, $newcopy);
} else {
imagejpeg($tci, $newcopy, 84);
}
}
// ------------- THUMBNAIL (CROP) FUNCTION -------------
// Function for creating a true thumbnail cropping from any jpg, gif, or png image files
function ak_img_thumb($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$src_x = ($w_orig / 2) - ($w / 2);
$src_y = ($h_orig / 2) - ($h / 2);
$ext = strtolower($ext);
$img = "";
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png"){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
imagecopyresampled($tci, $img, 0, 0, $src_x, $src_y, $w, $h, $w, $h);
if ($ext == "gif"){
imagegif($tci, $newcopy);
} else if($ext =="png"){
imagepng($tci, $newcopy);
} else {
imagejpeg($tci, $newcopy, 84);
}
}

  1. Insert in Row_Inserted & Row_Updated

$fileName = $rsnew['mimg'];
$kaboom = explode(".", $fileName); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension

$target_file = "../upload/content/mini/$fileName";
$resized_file = "../upload/content/mini/$fileName";
$wmax = 300;
$hmax = 300;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);

// ----------- End Adams Universal Image Resizing Function ----------
// ------ Start Adams Universal Image Thumbnail(Crop) Function ------
$target_file = "../upload/content/mini/$fileName";
$thumbnail = "../upload/content/mini/$fileName";
$wthumb = 124;
$hthumb = 124;
ak_img_thumb($target_file, $thumbnail, $wthumb, $hthumb, $fileExt);

It work! )))


anoopcyber
User
Posts: 1

Post by anoopcyber »

Hello,

Thanks for posting good help.
I am using phpmaker11 when I updated codes as per the tutorial it is giving error.

Notice: Undefined index: mimg in C:\xampp\htdocs\cyber\membersinfo.php on line 1048

Fatal error: Call to undefined function ak_img_resize() in C:\xampp\htdocs\cyber\membersinfo.php on line 1055

Any idea?


Post Reply