Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function crop(){
- $sourceImg = @imagecreatefromstring(@file_get_contents($_FILES["image"]["tmp_name"]));
- if ($sourceImg === false){
- echo base_url("assets/upload/image/images/1.png");
- exit;
- }
- // makeDP
- $sourcePath = $_FILES["image"]["tmp_name"];
- $design = (
- isset($_POST["design"]) ? $_POST["design"] : 0
- );
- if(in_array($design, array(0, 1, 2)))
- $design = "frame-$design.png";
- else
- exit;
- $src = imagecreatefromstring(file_get_contents($sourcePath));
- $fg = imagecreatefrompng(base_url("localhost/weboo/assets/upload/image/produk/$design"));
- list($width, $height) = getimagesize($sourcePath);
- $croppedFG = imagecreatetruecolor($width, $height);
- $background = imagecolorallocate($croppedFG, 0, 0, 0);
- // removing the black from the placeholder
- imagecolortransparent($croppedFG, $background);
- imagealphablending($croppedFG, false);
- imagesavealpha($croppedFG, true);
- imagecopyresized($croppedFG, $fg, 0, 0, 0, 0, $width, $height, 400, 400);
- // Start merging
- $out = imagecreatetruecolor($width, $height);
- imagecopyresampled($out, $src, 0, 0, 0, 0, $width, $height, $width, $height);
- imagecopyresampled($out, $croppedFG, 0, 0, 0, 0, $width, $height, $width, $height);
- ob_start();
- imagepng($out);
- $image = ob_get_clean();
- // makeDPend
- $str="";
- $chars = "addzifiabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- $size = strlen($chars);
- for($i = 0;$i < 10;$i++) {
- $str .= $chars[rand(0,$size-1)];
- }
- $url = $str;
- $loc = base_url("assets/upload/image/order/") . $url . ".png";
- file_put_contents($loc, $image);
- echo $loc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement