Image Resizing Script required - a better one...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

You could in theory download the Imagine library manually, set up your own autoloading, and thereby bypass Composer. Seems unnecessarily complicated to me, though. A few simple composer require saves you from writing tons of boilerplate.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

I just tried.
Attachments
screenshot of error as it runs
screenshot of error as it runs
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

Having not used Windows since Win7 was new, I'm afraid I'll be worse than useless at helping you resolve that. You could try the manual installation. Otherwise, you'll need to rely on Google to get that installed.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

Bugger.
What I am going to do in the meantime, is send my older code, with the longer-winded script to the guys we are doing this with to see if they can fathom how to make it work without additional libraries.

If it were to be done by a consumer, 'speed' may be important. But it isn't.
Does make one wonder how it works on Wordpress. Or maybe that uses a different engine for resizing. Though I Think that does it on the fly, as it is requested at user end.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

simonmlewis wrote:Bugger.
What I am going to do in the meantime, is send my older code, with the longer-winded script to the guys we are doing this with to see if they can fathom how to make it work without additional libraries.
Fair enough for the meantime, but I strongly advise against giving up on Composer. It's not really optional for modern PHP development. Wish I could help more, but haven't touched Windows in ages.
simonmlewis wrote:Does make one wonder how it works on Wordpress.
You could just look at their code.
simonmlewis wrote:Though I Think that does it on the fly, as it is requested at user end.
Only the first time a particular size is requested. Once it's saved to the disk, that's what gets served.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

Going to require some digging, but you could start here:
https://github.com/WordPress/WordPress/ ... d.php#L142
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

Yes so it must check for each image shown, if it exists or not. And if not, it then creates it on the fly.
That might even be a better way of doing it. And when Admin delete the main image, it checks if there are the other three versions on the server, and delete those.

But I am assuming we need Composer to do this 'on the fly' stuff?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

Take a look at your old code. Take a look at the WordPress code. Heck, take a look at the Imagine code. It can all be done using PHP's built-in functionality. The point of leveraging third-party libraries is that the heavy lifting is already done for you and you can just call it via a simple public API.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

It's installed. There was some issue, but when I Tried it again, it worked.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

I'm still getting that error. It was installed using the default settings, so would in theory run for all sites on my laptop.
But those two line errors show up.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

Which errors?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

Warning: require_once(C:\xampp\phpMyAdmin\site-wide/vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\phpMyAdmin\site-wide\includes\a_home.inc on line 616

Fatal error: require_once(): Failed opening required 'C:\xampp\phpMyAdmin\site-wide/vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\phpMyAdmin\site-wide\includes\a_home.inc on line 616

Line 616 is this:
require_once dirname(__DIR__) . '/vendor/autoload.php';
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

Have you created your composer.json file? Are you pulling in Imagine? Are you looking for the autoload file in the right place?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Image Resizing Script required - a better one...

Post by simonmlewis »

That page you sent doesn't state about creating a composer.json file. I'm using that code you sent me.
require_once dirname(__DIR__) . '/vendor/autoload.php';

$imagine = new Imagine\Gd\Imagine();
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Image Resizing Script required - a better one...

Post by Celauran »

https://getcomposer.org/doc/01-basic-usage.md

You need to tell composer which packages you need. For this case, calling this should suffice:

Code: Select all

composer require imagine/imagine
Alternately, create a composer.json in your project's root directory with the following contents:

Code: Select all

{
    "require": {
        "imagine/imagine": "^0.6.3"
    }
}
and run composer install
Post Reply