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

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 »

Also it looks like if I change the [] fpr (), I cannot use =>.............. ?
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:ahhhhhhhhhhhhh
So for now, how do I edit the $widths to accept it on this server until we update?
Where? getWidths? Just return array() instead of [].
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 »

Code: Select all

if (isset($resize))
{
  if ($resize == "categories" || $resize == "products")
  {
    // An array of widths, keyed by target screen size
$widths = (
    '475' => 237,
    '768' => 384,
    '1920' => 451,
);
  }
  elseif ($resize == "wide")
  {
  // An array of widths, keyed by target screen size
$widths = (
    '475' => 237,
    '768' => 384,
    '1920' => 950,
);
  }
  elseif ($resize == "desktopslide")
  {
  // An array of widths, keyed by target screen size
$widths = (
    '475' => 475,
    '768' => 768,
    '1920' => 1920,
);
  }  
}
If I make these (), I get an error on
[text]Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\xampp\phpMyAdmin\sote-wide\includes\a_page.inc on line 538[/text]
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:Also it looks like if I change the [] fpr (), I cannot use =>.............. ?
For assigning values to array keys? Absolutely you can.

5.4+

Code: Select all

// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
    switch($resize_option) {
        case 'categories':
        case 'products':
        case 'stockbanners':
            $widths = [
                '475' => 237,
                '768' => 384,
                '1920' => 451,
            ];
            break;
        case 'wide':
            $widths = [
                '475' => 237,
                '768' => 384,
                '1920' => 950,
            ];
            break;
        case 'desktopslide':
            $widths = [
                '475' => 475,
                '768' => 768,
                '1920' => 1920,
            ];
            break;
        default:
            $widths = [];
            break;
    }

    return $widths;
}
PHP 5.3.x

Code: Select all

// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
    switch($resize_option) {
        case 'categories':
        case 'products':
        case 'stockbanners':
            $widths = array(
                '475' => 237,
                '768' => 384,
                '1920' => 451,
            );
            break;
        case 'wide':
            $widths = array(
                '475' => 237,
                '768' => 384,
                '1920' => 950,
            );
            break;
        case 'desktopslide':
            $widths = array(
                '475' => 475,
                '768' => 768,
                '1920' => 1920,
            );
            break;
        default:
            $widths = array();
            break;
    }

    return $widths;
}
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 »

Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
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:Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
What json files? What's the error? Only json file I'm aware of is composer.json, which should be part of your deploy.
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 »

What about in the function, as it doesn't like this, and it is probably because of $widths[], but it has return $widths at the end.

Code: Select all

// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
    switch($resize_option) {
        case 'categories':
        case 'products':
        case 'stockbanners':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 451,
            );
            break;
        case 'wide':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 950,
            );
            break;
        case 'desktopslide':
            $widths = (
                '475' => 475,
                '768' => 768,
                '1920' => 1920,
            );
            break;
        case 'thumbnails':
            $widths = (
    '475' => 237,
    '768' => 384,
    '1920' => 451,
    '2520' => 600,
            );
            break;            
        default:
            $widths = [];
            break;
    }

    return $widths;
}
Can I just remove $widths =[]; ??
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 »

Celauran wrote:
simonmlewis wrote:Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
What json files? What's the error? Only json file I'm aware of is composer.json, which should be part of your deploy.
Oh. Actually there are no json files in vendor, but since 'vendor' is in the require code, I Assume it should be in the live server too.

I can see composer.json in my root. So if I manually upload that to the root of our beta site, do you think it would "find" where the files were installed on the server??
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:What about in the function, as it doesn't like this, and it is probably because of $widths[], but it has return $widths at the end.

Code: Select all

// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
    switch($resize_option) {
        case 'categories':
        case 'products':
        case 'stockbanners':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 451,
            );
            break;
        case 'wide':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 950,
            );
            break;
        case 'desktopslide':
            $widths = (
                '475' => 475,
                '768' => 768,
                '1920' => 1920,
            );
            break;
        case 'thumbnails':
            $widths = (
    '475' => 237,
    '768' => 384,
    '1920' => 451,
    '2520' => 600,
            );
            break;            
        default:
            $widths = [];
            break;
    }

    return $widths;
}
Can I just remove $widths =[]; ??
Look at my example above. You can't just use (), you need to use the old array syntax, array().
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:
Celauran wrote:
simonmlewis wrote:Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
What json files? What's the error? Only json file I'm aware of is composer.json, which should be part of your deploy.
Oh. Actually there are no json files in vendor, but since 'vendor' is in the require code, I Assume it should be in the live server too.

I can see composer.json in my root. So if I manually upload that to the root of our beta site, do you think it would "find" where the files were installed on the server??
No. Ideally you upload your composer.json and composer.lock files and then run composer install on the server. If that doesn't work, say because you don't have shell access on the server, then you'd need to upload your vendor directory as well.
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've uploaded the vendor files.
IT still has issues, most likely because of PHP versions and the scripts.

It now doesn't like this:

Code: Select all

array_map('unlink', glob("images/pages/$new_filename*.$new_ext"));
[text] mod_fcgid: stderr: PHP Warning: array_map(): Argument #2 should be an array in /var/www/vhosts/site.co.uk/subdomains/sand.site.co.uk/httpdocs/includes/a_page.inc on line 518, referer: http://sand.site.co.uk/a_page[/text]
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 »

Also within the function, do you mean the $widths should be like this?

Code: Select all

// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
    switch($resize_option) {
        case 'categories':
        case 'products':
        case 'stockbanners':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 451,
            );
            break;
        case 'wide':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 950,
            );
            break;
        case 'desktopslide':
            $widths = (
                '475' => 475,
                '768' => 768,
                '1920' => 1920,
            );
            break;
        case 'thumbnails':
            $widths = (
    '475' => 237,
    '768' => 384,
    '1920' => 451,
    '2520' => 600,
            );
            break;            
        default:
            $widths = ();
            break;
    }

    return $widths;
}
Or...
[syntax]
default:
break;
}

return $widths();
}[/syntax]
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:It now doesn't like this:

Code: Select all

array_map('unlink', glob("images/pages/$new_filename*.$new_ext"));
[text] mod_fcgid: stderr: PHP Warning: array_map(): Argument #2 should be an array in /var/www/vhosts/site.co.uk/subdomains/sand.site.co.uk/httpdocs/includes/a_page.inc on line 518, referer: http://sand.site.co.uk/a_page[/text]
http://php.net/manual/en/function.glob.php

glob returns an empty array if it doesn't find anything, returns false on error. The error message above suggests the latter is happening. Pull that out into its own variable and inspect what's going on.
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:Also within the function, do you mean the $widths should be like this?

Code: Select all

// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
    switch($resize_option) {
        case 'categories':
        case 'products':
        case 'stockbanners':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 451,
            );
            break;
        case 'wide':
            $widths = (
                '475' => 237,
                '768' => 384,
                '1920' => 950,
            );
            break;
        case 'desktopslide':
            $widths = (
                '475' => 475,
                '768' => 768,
                '1920' => 1920,
            );
            break;
        case 'thumbnails':
            $widths = (
    '475' => 237,
    '768' => 384,
    '1920' => 451,
    '2520' => 600,
            );
            break;            
        default:
            $widths = ();
            break;
    }

    return $widths;
}
Or...
[syntax]
default:
break;
}

return $widths();
}[/syntax]
No, see my post here: viewtopic.php?f=1&t=143432&p=707696#p707687

You need the array keyword in there.
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 understand. It's basically throw a fit because the image I want to delete, is not there.
So I am trying to upload an image, hoping it will create the other three as well.
It's now not upload an image.
It does add a row in the database.
It doesn't show anything in the error logs.
And no error is showing on screen.

In my upload script I have a small animation at the top "image uploading, one moment", then it returns to the admin screen.
It's not getting past that, presumably because it's getting blocked within the upload code.

I was hoping to see an error in the logs for not being able to find composer. But I have a feeling, a nagging feeling it's finding the files, but the files cannot locate the composer "engine" installed on the server.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply