sudkrishna / myimagecrop
Crop image upload widget by Sud
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:CSS
Type:yii2-extension
This package is not auto-updated.
Last update: 2024-04-13 16:45:53 UTC
README
install require - sudkrishna/myimagecrop":"dev-master" public function actionUploadimage() {//i $valid_exts = array('jpeg', 'jpg', 'png', 'gif'); $max_file_size = 200 * 1024; #200kb $nw = $nh = 200; # image with # height if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ( isset($_FILES['image']) ) { $ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); if (in_array($ext, $valid_exts)) { $path = 'uploads/' . uniqid() . '.' . $ext; $size = getimagesize($_FILES['image']['tmp_name']); $x = (int) $_POST['x']; $y = (int) $_POST['y']; $w = (int) $_POST['w'] ? $_POST['w'] : $size[0]; $h = (int) $_POST['h'] ? $_POST['h'] : $size[1]; $data = file_get_contents($_FILES['image']['tmp_name']); $vImg = imagecreatefromstring($data); $dstImg = imagecreatetruecolor($nw, $nh); imagecopyresampled($dstImg, $vImg, 0, 0, $x, $y, $nw, $nh, $w, $h); imagejpeg($dstImg, $path); imagedestroy($dstImg); return "<img src='$path' />"; } else { return 'unknown problem! Please select Image and cordinates'; } } else { return 'file not set'; } } else { return 'bad request!'; } }//i end of actionUploadimage()