claviska / SimpleImage

A PHP class that makes working with images and GD as simple as possible.
MIT License
1.38k stars 383 forks source link

PHP Fatal error: Uncaught Error: Class 'SimpleImage' not found in #285

Closed barnamah closed 3 years ago

barnamah commented 3 years ago

Hello, I have SimpleImage.php version 2.5.5 and in the same folder I have . If I don't included it inside a function it works. I am using it like this and it works perfectly. Thank you.

$img->load($sourceFile)->fit_to_width($STNG['ThumbWidth'])->save($newThumbFile);

$img->load($sourceFile)->best_fit($STNG['prodImageWidthMax'], $STNG['prodImageHeightMax'])->save($newFile);

I am using it in my test.php file like this

function makeThumb() {
  require 'SimpleImage.php';
  $img = new  SimpleImage();// make img object      
}

it gives error. Then in a page people mention to use

require 'SimpleImage.php';
$img = new  abeautifulsite\SimpleImage();// make img object      

still no luck.

I tried to use your new SimpleImage class but you don't have single example to initiate object where wen can use it. Now it is almost a week I am struggling with this. Please help.

Suggestion:

Please make example like above in a file. I learned it from the old SimpleImage.php class. Thanks

claviska commented 3 years ago

Does the example in the readme not work for you? https://github.com/claviska/SimpleImage#overview

barnamah commented 3 years ago

No it does not. it has >fromFile('image.jpg') I want to use like the above. I am using it in a loop over wither 1600 image. the >fromFile('image.jpg') needs file name and so many other details. I simply need to resize. so why I am I getting error?

barnamah commented 3 years ago

it says $image ->fromFile('image.jpg') // load image.jpg ->autoOrient() // adjust orientation based on exif data ->resize(320, 200) // resize to 320x200 pixels ->flip('x') // flip horizontally ->colorize('DarkBlue') // tint dark blue ->border('black', 10) // add a 10 pixel black border ->overlay('watermark.png', 'bottom right') // add a watermark image ->toFile('new-image.png', 'image/png') // convert to PNG and save a copy to new-image.png ->toScreen(); // output to the screen there is not best fit. Also why you used namespace. it should have been simple class with functions. I have also posted similar question here https://stackoverflow.com/questions/69034772/simpleimage-php-is-not-working-when-included

claviska commented 3 years ago

Please follow the example and review the current API docs and ensure you’re using the current version. You seem to be mixing up the old abeautifulsite namespace with the new one.

I can confirm that the example shown works, as does the one in /example/index.php. As this tracker is for bugs and features, and since you have an open issue on SO, I’m going to close this question out.