/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CreateCharacterRequest $request) { $sInputImageName = str_replace(' ', '_', Input::get('character_name') . '_' . $request->file('character_avatar')->getClientOriginalName()); $sImageName = rand(1, 1000000) . '_' . Session::get('user')['id'] . '_' . $sInputImageName; /*$request->file('character_avatar')->move(base_path().'/public/avatars/characters/normal/', $sImageName);*/ $request->file('character_avatar')->move(base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_NORMAL, $sImageName); $filename = base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_NORMAL . $sImageName; $jpeg_quality = 90; $targ_w = $targ_h = intval(150); switch ($request->file('character_avatar')->getClientOriginalExtension()) { case 'jpeg': case 'jpg': $source = imagecreatefromjpeg($filename); $img_r = imagecreatefromjpeg($filename); $dst_r = imagecreatetruecolor($targ_w, $targ_h); imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), $targ_w, $targ_h, Input::get('w'), Input::get('h')); //imagejpeg($dst_r, base_path().'/public/avatars/characters/mini/'. $sImageName, $jpeg_quality); header('Content-type: image/jpeg'); imagejpeg($dst_r, base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, $jpeg_quality); break; case 'png': $source = imagecreatefrompng($filename); $img_r = imagecreatefrompng($filename); $dst_r = imagecreatetruecolor($targ_w, $targ_h); imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), $targ_w, $targ_h, Input::get('w'), Input::get('h')); //imagejpeg($dst_r, base_path().'/public/avatars/characters/mini/'. $sImageName, $jpeg_quality); header('Content-type: image/jpeg'); imagepng($dst_r, base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, 9); break; case 'gif': $source = imagecreatefromgif($filename); $img_r = imagecreatefromgif($filename); $dst_r = imagecreatetruecolor($targ_w, $targ_h); imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), $targ_w, $targ_h, Input::get('w'), Input::get('h')); //imagejpeg($dst_r, base_path().'/public/avatars/characters/mini/'. $sImageName, $jpeg_quality); header('Content-type: image/jpeg'); imagegif($dst_r, base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, $jpeg_quality); break; default: $source = imagecreatefromjpeg($filename); break; } /*$proceed = imagecopyresized($thumb, $source, $request->get('x'), $request->get('y'), $request->get('x'), $request->get('y'), $request->get('w'), $request->get('h'), $width, $height); if(!$proceed){ die("error"); }*/ $aPhoto = Photo::create(['user_id' => Session::get('user')['id'], 'photo_type' => Photo::PHOTO_TYPE_CHARACTER, 'photo_link' => Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, 'status' => Photo::PHOTO_STATUS_DEFAULT]); if ($request->all()) { $aCharacter = Character::create(['user_id' => Session::get('user')['id'], 'families_id' => Input::get('families_id'), 'character_name' => Input::get('character_name'), 'character_age' => Input::get('character_age'), 'character_avatar' => Photo::PHOTO_LINK_AVATAR_CHARACTER_NORMAL . $sImageName, 'character_avatar_mini' => Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, 'character_description' => Input::get('character_description'), 'photo_id' => $aPhoto['id']]); Update::create(['user_id' => Session::get('user')['id'], 'update_type' => Update::UPDATE_TYPE_CHARACTER, 'character_id' => $aCharacter['id'], 'status' => Update::UPDATE_STATUS_ACTIVE]); return redirect('user'); } }