PHP code example of daycode / stup-images

1. Go to this page and download the library: Download daycode/stup-images library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daycode / stup-images example snippets


use DayCod\StupImages\StupImages;
use DayCod\StupImages\Functions\StupImageFunctions;

(new StupImages($filename, $path, $width, $height))->StupImagesToStorage($new_image_file, $old_image_file = null)

$filename = "Filename cannot be an empty string ``";
$path = "Path cannot be an empty string ``";

$width = "Width input must be an integer";
$width = "Width Basically is Dimension and Dimension would`nt be lower than zero or negative";

$height = "Height input must be an integer";
$height = "Height Basically is Dimension and Dimension would`nt be lower than zero or negative";

(new StupImageFunctions())->getFileName($old_image_file);

// $old_image_file is a value from the database table where you stored at

public function store(Request $request): RedirectResponse
{
    $data = [
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password),
    ];

    $image = $request->file('images');
    $imageName = hexdec(uniqid()).'.'.$image->getClientOriginalExtension();
    $dir = 'upload/images/';
    $save_path = 'upload/images/'.$imageName;

    Image::make($realImage)->resize($width, $height)->save(public_path($save_path));

    $data['user_profile_img'] = $save_path;

    User::create($data);

    return redirect()->back()->with('success', 'User Successfully Created');
}

public function store(Request $request): RedirectResponse
{
    User::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password),
        'user_profile_img' => (new StupImages('user-profile', 'profile', 300, 300))->StupImagesToStorage($request->file('user_profile_img')),
    ]);

    return redirect()->back()->with('success', 'User Successfully Created');
}

public function update(Request $request, $id): RedirectResponse
{
    $data = [
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password),
    ];

    $user = User::findOrFail($id);

    if ($request->file('images')) {
        $image = $request->file('images');
        $imageName = hexdec(uniqid()).'.'.$image->getClientOriginalExtension();
        $dir = 'upload/images/';
        $save_path = 'upload/images/'.$imageName;
    
        Image::make($realImage)->resize($width, $height)->save(public_path($save_path));
    
        $data['images'] = $save_path;
    
        $user->update($data);
    } else { $user->update($data); }

    return redirect()->back()->with('success', 'User Successfully Updated');
}

public function update(Request $request, $id): RedirectResponse
{
    $user = User::find($user_id);
    $user->update([
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password),
        'user_profile_img' => (is_null($request->file('user_profile_img'))) 
            ? $user->fresh()->user_profile_img 
            : (new StupImages('user-profile', 'profile', 300, 300))
                ->StupImagesToStorage($request->file('user_profile_img'), $user->fresh()->user_profile_img),
    ]);
}
bash
composer dump-autoload && php artisan optimize:clear
bash
php artisan storage:link