1

Controller :

public function index()
{
    if (!file_exists("uploads/profiles/".\Auth::User()->id.".jpeg")) {
        $image_content = File::get("uploads/profiles/default.jpg");
        $image =  response($image_content, 200)->header('Content-Type', 'image/jpeg');
        $size = getimagesize($image);
        $aspectratio = $size[0]/$size[1];
        $img_thumbnail = Image::make($image)->resize(50*$aspectratio,50);
        $img_profile = Image::make($image)->resize(160*$aspectratio,160);
        $imgname = \Auth::User()->id;
        $img_thumbnail->save('uploads/thumbnails/'.$imgname.".jpeg");
        $img_profile->save('uploads/profiles/'.$imgname.".jpeg");
}

Error : : failed to open stream: No such file or directory.

Actually, I want to fetch the default.jpg image and save it to two other folders with different extension.

4
  • @zkanoca That won't do anything. Commented Jan 13, 2016 at 22:45
  • 3
    The output you're seeing is correct. You need to have the response serve the right Content-Type header though. Commented Jan 13, 2016 at 22:46
  • Are you using a Mac or a Linux or Windows ? Commented Jan 14, 2016 at 1:02
  • I think you need to give a proper permission to your folder, that you want to output the image into. Commented Jan 14, 2016 at 1:03

3 Answers 3

1
        if( !file_exists('uploads/thumbnails/'. $folder)){
            @mkdir('uploads/thumbnails/'. $folder, 0755);
        }
        if( !file_exists('uploads/profiles/'. $folder)){
            @mkdir('uploads/profiles/'. $folder, 0755);
        }

        $img = 'uploads/profiles/'. \Auth::User()->id. '.jpeg';
        if ( !file_exists($img)){
            $save_extension = '.jpeg';
            Image::make($img)
                ->resize(50, null, function ($constraint) {
                    $constraint->aspectRatio();
                })->save('uploads/thumbnails/' . \Auth::User()->id . $save_extension);
            Image::make($img)
                ->resize(160, null, function ($constraint) {
                    $constraint->aspectRatio();
                })->save('uploads/profiles/' . \Auth::User()->id . $save_extension);
        }

http://image.intervention.io/api/resize

Sign up to request clarification or add additional context in comments.

3 Comments

But, I have to fetch the default.jpg from the folder '/uploads/profiles/default.jpg' and then save it to another destination "'uploads/thumbnails/' . \Auth::User()->id .'.jpeg'. But in your solution I'm not able to fetch default.jpg .
( !file_exists('uploads/profiles/'. \Auth::User()->id. '.jpeg')){ $save_extension = '.jpeg'; Image::make('/uploads/profiles/default.jpg') ->resize(50, null, function ($constraint) { $constraint->aspectRatio(); })->save('uploads/thumbnails/' . \Auth::User()->id . $save_extension); Image::make('/uploads/profiles/default.jpg') ->resize(160, null, function ($constraint) { $constraint->aspectRatio(); })->save('uploads/profiles/' . \Auth::User()->id . $save_extension); }
Change Image::make($img) to Image::make('/uploads/profiles/default.jpg'). '/uploads/profiles/default.jpg' exists in folder ?
0
public function index()
{
    if (!file_exists("uploads/profiles/".\Auth::User()->id.".jpeg")) {
        $image = File::get("uploads/profiles/default.jpg");
        return response($image)->header('Content-Type', 'image/jpeg');
}

1 Comment

Yes, I have done this but I modified the question. And I'm stuck in this.
0

Make sure you're have the right permission to uploads/profiles/

chmod -R 777 /uploads/profiles/

1 Comment

Yes, permission is already given to folder because I've already saved the photos in that folder. But here the problem is fetching the default.jpg and then saving it to other destination. And when I'm fetching the default.jpg it's coming in blob, not in proper image which is not working with getimagesize

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.