I'm trying to resize my images using Intervention package in my laravel project. I'm able to store images using Storage facade, but when I store them with Image class it throws below error.
Can't write image data to path
(/var/www/commerce/storage/featureds/2-1537128615.jpg)
if ($request->has("featured_img")) {
$file_path = $request->get("featured_img");
$exp = explode("/",$file_path);
$filename = $exp[1];
$featured_path = "featureds/".$filename;
\Storage::copy($request->get("featured_img"), $featured_path);
\Image::make(\Storage::get($featured_path))->fit(400, 300)->save(storage_path($featured_path));
$product->media()->where("type", "featured")->update(["path" => $featured_path]);
}
How can I fix this ? Thanks for all your helps
Is there featureds directory in storage?
If no, you use mkdir to create directory because Intervention don't create directory automatically.
Related
What is the correct way to upload,update and get an image or file in laravel ? I had gone through laravel docs and other references but its confusing.Can anyone show a complete simple example for
any disk configuration in filesystems.php
a simple method to upload and update image in controller
and what will be the image full url?
input type file name is image you can store directly into images folder
return $path = $request->image->store('images');
Can anyone please help me to change the directory of image in fpdf?
I needed to fetch the image from database where it is saved as my customer has given me the image. I am using laravel 5.4.
****
But FPDF is searching for image in fpdf folder.
I want to change directory to the saved folder.
//Fetching logo from database
$pdf->Image($company->logo,'10','10','30','30');
//Directories where the image is saved
Image are saved in = (public/upload/logos [folder])
In case anyone needs the answer of changing the directory of image file to fetch it for laravel in fpdf !
$path = public_path() . '/upload/logos/';
$filepath = $path . $company->logo;
if(file_exists($filepath)) {
$pdf->Image($filepath,'10','10','30','30');
}
I have a form which lets the user upload the image file.
<div id="imageDiv">
Image Path : <input class="imageOption" type="file" id= "uploadImageFile" name="uploadImageFile" >
</div>
The problem comes when I try to fetch the path from temp folder. I won't be needing the image files after processing the request. When I try to fetch the path with something like this
$imagePath = $_FILES['uploadImageFile']['tmp_name'];
The path looks like C:\wamp\tmp\phpA123.tmp.
The API I'm using would require a path with extension of an uploaded image like this
C:\wamp\tmp\image.png
Couldn't figure out a way to do so unless I want to copy this image to some other upload folder and use it. I don't want these images logged in a server
Thanks
It would be helpful to know the specific API in use, but no well written file storage API should ever have to rely on the uploaded file name being used to store a file. You should be able to use the temp file contents in the API, and specify the file name separately.
In L5:
// Get the UploadedFile object
$file = Request::file('uploadImageFile');
// You can store this but should validate it to avoid conflicts
$original_name = $file->getClientOriginalName();
// This would be used for the payload
$file_path = $file->getPathName();
// Example S3 API upload
$s3client->putObject([
'Key' => $original_name, // This will overwrite any other files with same name
'SourceFile' => $file_path,
'Bucket' => 'bucket_name'
]);
If you want to get same output as -
$imagePath = $_FILES['uploadImageFile']['tmp_name'];
in Laravel, you can do something like this as described by #cdbconcepts -
$file = Request::file('uploadImageFile');
$imagePath = $file->getPathName()
I am using Codeigniter's image_lib library to resize my images, it is working fine but it renames the image as "original_name_thumb.ext". I dont want it to rename it by adding _thumb. I am saving them in new folders. So rename is not required.
just set thumb_marker = "";
$config["thumb_marker"] = "";
while setting config for image library and it should work fine. See docs
I'm using amazon s3 to store my images. For now I've got 3 different folders - temporary one to not accepted pictures, one for accepted and one for watermarked one.
When photo is being accepted it is copied to accepted and watermarked folders and deleted form temporary one.
The problem is with watermarked folder because I need to add watermark. During work in progress I've mocked method that is adding watermark like this:
protected function addWatermark($product)
{
$filterName = 'watermark';
$this->imagineFilterManager->getFilter($filterName)
->apply($this->imagine->open($product->getFilePath()))
->save($path, array('format' => "png"));
}
and it was pretty fine. But the problem is - mock was working on uploaded file, and FilePath was temporary file path to image.
Now I need to retrieve image from amazon s3, pass it to imagineFilterManager and save back at amazon s3 location. The problem is with retrieving photo.
I tried like this:
read method:
public function read($path)
{
return $this->fileSystem->read($path);
}
protected function addWatermark($product)
{
var_dump('addWatermark');
$filterName = 'watermark';
$path = $this->getShopPicturePath($product);
$file = $this->staticContentAdapter->read($path);
$file = imagecreatefromstring($file);
$this->imagineFilterManager->getFilter($filterName)
->apply($this->imagine->open($file))
->save($path, array('format' => "png"));
var_dump('filtered');exit;
}
but after this $this-imagine-open() returns
File Resource id #141 doesn't exist
The strange thing form me is that it is was possible for me to save image file on s3 using only path:
->save($path, array('format' => "png"));
but it is not possible to open file using only path:
->apply($this->imagine->open($file->getFilePath()))
It throws exceptions
File watermarked/asd_asd.png doesn't exist.