0
라이브러리를 사용하는 이미지에 워터 마크를 추가하려고합니다. 아래 코드는 입니다. 이미지를 업로드하거나 검색 할 때 동적으로 워터 마크를 구현해야합니다.라이브러리 또는 사용자 정의 개발을 사용하여 laravel을 사용하여 이미지를 업로드 할 때 워터 마크를 추가하는 방법
이미지의컨트롤러 코드
public function store(storeNewspaperJobFormValidation $request)
{
$values = $request->input();
list($city, $catagory) = $this->_gettingValues($values);
unset($values['city_id']);
unset($values['catagory_id']);
$values['slug'] = str_slug($values['organization_name'] . '-' . rand(1, 1000), '-');
if ($request->hasFile('image_file')) {
$request->file('image_file');
$filename = $request->image_file->getClientOriginalName();
$originalfile['image_file'] = $request->image_file->storeAs('public/newpaper_jobs', $filename);
$data = array_merge($values, $originalfile);
$newspaper = new newspaper_jobad($data);
$newspaper->save();
$insertedId = $newspaper->id;
$this->_saveCatagoryNewspaperJobadbAssociations($catagory, $insertedId);
$this->_saveNewspaperJobCities($city, $insertedId);
//a flash message shold be shown that data successfully created
flash('Data successfully added')->success();
return back();
} else
flash('Data Not Inserted Image is Missing')->success();
return back();
}
모델
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;
use Laravel\Scout\Searchable;
use Intervention\Image\Facades\Image;
class newspaper_jobad extends Model
{
use Searchable;
protected $fillable = ['organization_name', 'job_apply_link', 'job_description', 'city_id', 'province_id', 'sector_id', 'image_file', 'test_id', 'newspaper_id', 'catagory_id', 'slug', 'meta_keywords', 'meta_description', 'job_title'];
public function getFilePathAttribute($value)
{
$img = Image::make("public/newpaper_jobs/$value"); //your image I assume you have in public directory
$img->insert('public/favico.png', 'bottom-right', 10, 10); //insert watermark in (also from public_directory)
$img->save("public/Storage/newpaper_jobs/$value"); //save created image (will override old image)
return ($value); //return value
}
위치 워터 마크 이미지
public/favico.png
의 이미지 경로는'Image :: make (asset ('newpaper_jobs /'. $ value)) '와 같은'asset' 도우미를 사용하고, – devsourav
이 참조하면 도움이 될 것입니다. https://stackoverflow.com/questions/41182385/adding-watermark-on-image-from-databases-in-laravel-5-3 –