Page 5 of 37
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:22 am
by Celauran
simonmlewis wrote:So I now have a composer.json file in my project with that small bit of code you told me, anbout and a big composer.lock file.
Good. You should also have a vendor directory containing the Imagine library and any of its dependencies.
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:25 am
by simonmlewis
When running the script, I now get this:
[text]Fatal error: Class 'Imagine\Gd\Imagine' not found in C:\xampp\phpMyAdmin\site-wide\includes\a_home.inc on line 618[/text]
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:26 am
by Celauran
Did you require the autoloader?
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:27 am
by simonmlewis
This is in there.
require_once dirname(__DIR__) . '/vendor/autoload.php';
$imagine = new Imagine\Gd\Imagine();
After the initial upload of the core file, but before your main script. Basically exactly as you sent it to me.
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:28 am
by simonmlewis
And yes, I do see that in the structure of it now.
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:29 am
by simonmlewis
Code: Select all
// ADD ALL BANNERS (SQUARE AND DOUBLE)
if ($update == "addbanner")
{
if (isset($layertype))
{
$result = mysql_query ("SELECT id FROM products WHERE romancode = '$searchurl'");
$num_result = mysql_num_rows($result);
if ($num_result > 1)
{
$disableupload = "yes";
echo "<script>
window.location.replace('/a_home&status=duplicatecode')
</script>";
}
}
if (!isset($disableupload))
{
if ($stockbanner == "yes")
{
if ($searchurl != "")
{
mysql_query("INSERT INTO homepage (url, section, freetext, priority, content, homepromocolor, homepromotextcolor, stockbanner) VALUES ('$searchurl', '$section', '$freetext', '$priority', '$content', '$homepromocolor', '$homepromotextcolor', '$stockbanner')");
}
elseif ($searchurl == "")
{
mysql_query("INSERT INTO homepage (url, section, freetext, priority, content, homepromocolor, homepromotextcolor, stockbanner) VALUES ('$url', '$section', '$freetext', '$priority', '$content', '$homepromocolor', '$homepromotextcolor', '$stockbanner')");
}
echo "<script>
window.location.replace('/a_home')
</script>";
}
else
{
$target = $_SERVER['DOCUMENT_ROOT']."/images/pages/";
$random = (rand()%99999999);
$pic=($_FILES['homeimage']['name']);
$newname="$random"."$pic";
$target = $target . $newname;
if ($searchurl != "")
{
mysql_query("INSERT INTO homepage(url, image, section, freetext, priority, content, homepromocolor, homepromotextcolor, stockbanner) VALUES ('$searchurl', '$newname', '$section', '$freetext', '$priority', '$content', '$homepromocolor', '$homepromotextcolor', '$stockbanner')");
}
elseif ($searchurl == "")
{
mysql_query("INSERT INTO homepage(url, image, section, freetext, priority, content, homepromocolor, homepromotextcolor, stockbanner) VALUES ('$url', '$newname', '$section', '$freetext', '$priority', '$content', '$homepromocolor', '$homepromotextcolor', '$stockbanner')");
}
require_once dirname(__DIR__) . '/vendor/autoload.php';
$imagine = new Imagine\Gd\Imagine();
// An array of widths, keyed by target screen size
$widths = [
'475' => 237,
'768' => 384,
'1920' => 451,
];
// If we have an uploaded image without errors
if (!empty($_FILES) && isset($_FILES['homeimage']) && $_FILES['image']['error'] !== 0) {
$target_directory = __DIR__ . '/images/pages';
$pathinfo = pathinfo($_FILES['homeimage']['name']);
$prefix = (rand() % 99999999);
// Open the uploaded image with the Imagine library
$image = $imagine->open($_FILES['homeimage']['tmp_name']);
// Save the original
$image->save($target_directory . '/' . $pathinfo['basename']);
// Get image size
$box = $image->getSize();
// Resize
foreach ($widths as $key => $width) {
$ratio = $width / $box->getWidth();
$scaled_box = $box->scale($ratio);
$new_filename = "{$prefix}_{$pathinfo['filename']}{$key}.{$pathinfo['extension']}";
$image->resize($scaled_box)->save($target_directory . '/' . $new_filename);
}
}
//Writes the photo to the server
if(move_uploaded_file($_FILES['homeimage']['tmp_name'], $target))
{
echo "<script>
window.location.replace('/a_home')
</script>";
}
}
}}
}
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:30 am
by Celauran
Do you see imagine in the vendor directory? What version of PHP?
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:32 am
by simonmlewis
no i dont. I think it's 5.4 or 5.3.
xamp 3.2.1
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:34 am
by Celauran
Hmm. And you ran composer install? Do you have a vendor directory? Imagine only requires PHP 5.3.2, so that's not the issue.
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:35 am
by simonmlewis
Do I need to run something to make imagine run? I might have missed that...??
And yes I do. In there is two folders (composer, monolog). And one file: autoload.php.
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:38 am
by Celauran
monolog? What? What does your composer.json look like?
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:39 am
by simonmlewis
Earlier you said I need to include or make a json file so I did:
{
"require": {
"monolog/monolog": "1.0.*"
}
}
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:45 am
by Celauran
Yes, but
I gave you the specific contents. It's not finding Imagine because you required monolog and not imagine.
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:46 am
by simonmlewis
So can I just alter that json file?
Re: Image Resizing Script required - a better one...
Posted: Tue Mar 07, 2017 10:46 am
by Celauran
simonmlewis wrote:So can I just alter that json file?
Yes, and then re-run
composer install