Viewed   433 times

I just installed Intervention Image Class following instructions from here: http://image.intervention.io/getting_started/installation

I also added these 2 lines into config/app.php file:

'InterventionImageImageServiceProvider'

'Image' => 'InterventionImageFacadesImage'

When I open my website, i get this error:

Class 'InterventionImageImageServiceProvider' not found

Why is that and what should I do now?

 Answers

2

Step 1:

Add "intervention/image": "dev-master" to the “require” section of your composer.json file.

"require": {
    "laravel/framework": "4.1.*",
    "intervention/image": "dev-master"
},

Step 2:

Run CMD;
$ composer install

If you've got this warning:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

do $ composer update and then $ composer install

Step 3:

open the config/app.php file. Add this to the $providers array.

InterventionImageImageServiceProvider::class

Step 4:

Next add this to the $aliases array.

'Image' => InterventionImageFacadesImage::class

Step 5:

If there is an error;

Class 'InterventionImageImageServiceProvider' not found

try

$ composer update
Tuesday, October 11, 2022
 
nid
 
nid
4

If you upgraded to 8 from a previous version you are probably missing the autoload directive for the DatabaseFactories namespace in composer.json:

"autoload": {
    "psr-4": {
        "App\": "app/",
        "Database\Factories\": "database/factories/",
        "Database\Seeders\": "database/seeders/"
    }
},

You can also remove the classmap part, since it is no longer needed.

Run composer dump after making these changes.

Laravel 8.x Docs - Upgrade Guide - Database - Seeder and Factory Namespace

Wednesday, October 5, 2022
5

Try the imagecopyresized function,
which is built in,
need not to re-compile (your share hosting will be happy),
and provide almost simple feature for image processing

Jquery is clients javascript library,
it does not help with image processing

Tuesday, December 13, 2022
 
qiao
 
4

I believe I know the reason now.

The new class MemberInvitationSeeder wasn't in the autoloaded classes in the composer.json file.

It wasn't there because I added that class manually.

Now, going forward, if I add such classes again, what should I use in order for my class to automatically to the autoloader?

Sunday, October 2, 2022
 
itzhar
 
1

To my knowledge, you can’t resize the image before uploading it. (I could be wrong!) However, when you upload the image it goes into a temporary file. You can resize the temporary image and copy the resized image to its final destination.

This code was adapted from a snippet at FliquidStudios: Resizing images in PHP with GD and Imagick.

Since (it seems) you want to keep the width constant, you don’t really need to do a lot of ratio tests.

Update:

You should be able to simply use this in place of your original code. Most of it is unchanged.

<?php

// resizes an image to fit a given width in pixels.
// works with BMP, PNG, JPEG, and GIF
// $file is overwritten
function fit_image_file_to_width($file, $w, $mime = 'image/jpeg') {
    list($width, $height) = getimagesize($file);
    $newwidth = $w;
    $newheight = $w * $height / $width;

    switch ($mime) {
        case 'image/jpeg':
            $src = imagecreatefromjpeg($file);
            break;
        case 'image/png';
            $src = imagecreatefrompng($file);
            break;
        case 'image/bmp';
            $src = imagecreatefromwbmp($file);
            break;
        case 'image/gif';
            $src = imagecreatefromgif($file);
            break;
    }

    $dst = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    switch ($mime) {
        case 'image/jpeg':
            imagejpeg($dst, $file);
            break;
        case 'image/png';
            imagealphablending($dst, false);
            imagesavealpha($dst, true);
            imagepng($dst, $file);
            break;
        case 'image/bmp';
            imagewbmp($dst, $file);
            break;
        case 'image/gif';
            imagegif($dst, $file);
            break;
    }

    imagedestroy($dst);
}

// init file vars
$pic  = $_FILES['photo']['name'];
$target = 'uploads/' . basename( $_FILES['photo']['name']);
$temp_name = $_FILES['photo']['tmp_name'];
$type = $_FILES["photo"]["type"];

// Connects to your Database 
mysql_connect("hostname", "username", "password") or die(mysql_error()) ; 
mysql_select_db("database") or die(mysql_error()) ; 

// get form data
$name = mysql_real_escape_string(isset($_POST['name']) ? $_POST['name'] : 'No name');

//Writes the information to the database 
mysql_query("INSERT INTO `table` (name, photo) VALUES ('$name','$pic')") ; 

// resize the image in the tmp directorys
fit_image_file_to_width($temp_name, 200, $type);

//Writes the photo to the server
if(move_uploaded_file($temp_name, $target)) {

    //Tells you if its all ok 
    echo "The file ". basename( $_FILES['photo']['name'] ). " has been uploaded"; 

} else {

    //Gives and error if its not 
    echo "Sorry, there was a problem uploading your file."; 

}

?>
Monday, October 3, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :