Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with GetStockImage.php
07-25-2015, 10:22 PM, (This post was last modified: 07-25-2015, 10:38 PM by janb.)
#1
Problems with GetStockImage.php
Finally I got some time to look for a solution I've had when auto-creating images via GetStockImage.php (and function imagecreatefromjpg).

I have GD Graphics Library (php5-gd) installed and enabled but the function have newer worked (unavailable).

When using
Code:
if (extension_loaded('gd') && function_exists('gd_info')...
instead of
Code:
if (function_exists('imagecreatefromjpg')...
in for example Stocks.php everything works great and GetStockImage.php generates images.

It looks like imagecreatefromjpg is only for GD testing and not actively in use?
Suggests using the above test instead even though this maybe is a minor problem...

This is on a Debian wheezy Server w/Apache 2.2. / PHP 5.4.

Jan
Reply
07-26-2015, 02:35 AM,
#2
RE: Problems with GetStockImage.php
I believe the function name should correctly be imagecreatefromjpeg() not imagecreatefromjpg

Can you try changing this line to

if (function_exists('imagecreatefromjpeg')

and see if it works.

Thanks
Tim
Reply
07-26-2015, 02:50 AM, (This post was last modified: 07-26-2015, 05:14 AM by janb.)
#3
RE: Problems with GetStockImage.php
(07-26-2015, 02:35 AM)falkoner Wrote: I believe the function name should correctly be imagecreatefromjpeg() not imagecreatefromjpg

Can you try changing this line to

if (function_exists('imagecreatefromjpeg')

and see if it works.

Thanks
Tim

Of course! Should have seen this!
Now it's working..
There are several other script where this function (with typo) is used..

Edit:
SelectProduct.php
StockClone.php
FixedAssetItems.php
Stocks.php
I think i have had a look at this before and i think i also removed the comment from this line: //include ('includes/session.inc'); from GetStockImage.php which is needed for $FilePath = $_SESSION['part_pics_dir'] . '/'; and for this to work correctly.

I am not sure why this line is commented out.
Is this script on it's way to be deprecated or is the intention to use this further?
Most webERP scripts is also using alternatives by direct access to images.

Btw, WorkOrderEntry.php is using (for some reason)
if (function_exists('imagecreatefrompng') ...and then alternative access

Jan
Reply
07-26-2015, 07:06 AM,
#4
RE: Problems with GetStockImage.php
Hi Jan, IIRC the reason for using this function was to overlay the part code on top of the image. You are correct those other scripts need changing.

IMHO it would be best to have a Switch statement that used the png or the jpeg function depending on the type of the image. Shouldn't be too hard to write though I haven't checked.

Thanks
Tim
Reply
07-26-2015, 07:44 AM, (This post was last modified: 07-26-2015, 08:12 AM by janb.)
#5
RE: Problems with GetStockImage.php
Tim

Yes, i can see there is part-code overlay in the script, nice to have!

I just checked GetStockImage.php, the code for png/jpg extension check is there already and it works.
The only thing to do is to change the scripts with typos and remove comment slashes in GetStockImage.php for including session.inc That's it as far i can see for the script to work.
In additional should all "hard-coded" .jpg be changed to a switch statement as you mentioned.

Jan
Reply
07-26-2015, 06:54 PM,
#6
RE: Problems with GetStockImage.php
Hi Jan,

Yes, looking at it the code is already in GetStockImage.php

Given that, I would say we should replace all the

if (function_exists('imagecreatefromjpg')

lines with your initial suggestion of

if (extension_loaded('gd') && function_exists('gd_info')

This should be in all the scripts which call GetStockImage.php which I see as:
ContractBOM.php
FixedAssetItems.php
SalesCategories.php
SelectProduct.php
StockClone.php
Stocks.php
WorkOrderEntry.php
WorkOrderIssue.php

We can then remove the redundant

if (!function_exists('imagecreatefrompng')) {
$Title = _('Image Manipulation Script Problem');
include('includes/header.inc');
prnMsg(_('This script requires the gd image functions to be available to php - this needs to be enabled in your server php version before this script can be used'), 'error');
include('includes/footer.inc');
exit;
}
code from GetStockImage.php

Would you agree?

Tim
Reply
07-26-2015, 11:59 PM, (This post was last modified: 07-27-2015, 12:33 AM by janb.)
#7
RE: Problems with GetStockImage.php
Yes, agree Tim
Had a double-check for scrips which call GetStockImage.php,
SelectCreditItems.php does also call GetStockImage.php but the other way around.

Before the election between jpg and png can be done there is additional scripts with code like file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') that need to be changed also (maybe there are others too);

Contracts.php
GoodsReceived.php
Manufacturers.php
PDFPriceList.php
PO_Items.php
PrintWOItemSlip.php
SelectCreditItems.php
StockDispatch.php
SupplierTenderCreate.php
SupplierTenders.php
Z_ChangeStockCode.php
Z_ItemsWithoutPicture.php

Jan

Quote:if (!function_exists('imagecreatefrompng')) {
$Title = _('Image Manipulation Script Problem');
include('includes/header.inc');
prnMsg(_('This script requires the gd image functions to be available to php - this needs to be enabled in your server php version before this script can be used'), 'error');
include('includes/footer.inc');
exit;
}
code from GetStockImage.php

I would suggest a more general check for GD not imagecreatefrompng or imagecreatefromjpeg.
..and i don't think both extension_loaded('gd') and function_exists('gd_info') is necessary.
if (!extension_loaded('gd') should be sufficient and precise
Reply
07-27-2015, 08:11 PM, (This post was last modified: 07-27-2015, 11:13 PM by janb.)
#8
RE: Problems with GetStockImage.php
This is a test I have used in another project as an alternative to switch
..and for example as an alternative to if(!file_exists($_SESSION['part_pics_dir'] . '/' .$myrow['stockid'].'.jpg') ) in Z_ItemsWithoutPicture.php

Code:
if (!$ImageFile = glob(getcwd() . '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{png,jpg,jpeg,bmp,gif}', GLOB_BRACE)) {
..
}
using some more extensions to demonstrate the capabilities.
..but this is only a proposal.

Edit:
This may of course also be used to pick up the first available picture type in the pattern
Code:
$ImageFile = glob(getcwd() . '/' . $_SESSION['part_pics_dir'] . '/' . $stockid . '.{png,jpg,jpeg,bmp,gif}', GLOB_BRACE);
if ($ImageFile) {
    echo '<img src="' . str_replace(getcwd().'/','',$ImageFile[0]) . '"/>';
    ..or whatever
} else {
    echo '..do something else';
}
Jan
Reply
07-30-2015, 07:50 PM,
#9
RE: Problems with GetStockImage.php
Hi Jan,

Sorry for the delay in replying.

Does it therefore make sense to take everything into GetStockImage.php, the check for the extension, the check for the file, and any error handling that is necessary, and just include the GetStockImage.php script wherever necessary. This would seem to make the most sense to me, can you see any harm in this.

I agree that your file checking and extension checking lines are superior to the ones I was saying.

Thanks
Tim
Reply
02-26-2016, 06:31 AM, (This post was last modified: 02-28-2016, 11:18 AM by janb.)
#10
RE: Problems with GetStockImage.php
Hi

I have noticed that nothing happen with GetStockImage.php and I want to pick up this thread again if you don't mind.

I have used various workarounds for a while to support both jpg and png for stock images but decided to try to find an easier way to check for this.
I ended up with this simple check to determine if its png, jpg or jpeg.
(Notice use of double parentheses to avoid php strict error for reset() if no files found causing missing parameter)

Code:
$imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $StockID . '.{png,jpg,jpeg}', GLOB_BRACE)));

Then i have used $imagefile in what we kind of agreed to check for GD and if the file exist for GetStockImage.php and for use in the img link:

(Example from SelectProduct.php)
Code:
if (extension_loaded ('gd') && function_exists ('gd_info') && file_exists ($imagefile) ) {
    if ($_SESSION['ShowStockidOnImages'] == '0') {
        $StockImgLink = '<img src="GetStockImage.php?automake=1&amp;textcolor=FFFFFF&amp;bgcolor=CCCCCC'.
                            '&amp;StockID='.urlencode($StockID).
                            '&amp;text='.
                            '&amp;width=100'.
                            '&amp;height=100'.
                            '" alt="" />';
    } else {
        $StockImgLink = '<img src="GetStockImage.php?automake=1&amp;textcolor=FFFFFF&amp;bgcolor=CCCCCC'.
                            '&amp;StockID='.urlencode($StockID).
                            '&amp;text='. $StockID .
                            '&amp;width=100'.
                            '&amp;height=100'.
                            '" alt="" />';
    }
} else {
    if (isset ($StockID) AND file_exists ($imagefile) ) {
        $StockImgLink = '<img src="' . $imagefile . '" height="100" width="100" />';
    } else {
        $StockImgLink = _('No Image');
    }
}

FYI
I have also removed the comment slashes in GetStockImage.php line 5 as well as
line 52-58 as agreed.
Hope this can be implemented in the project soon.

But of course, support for png, jpg and jpeg just as a suggestion and a wish Smile

There is a lot work to do in several scripts if this is interesting and i have some scripts ready for test.
FixedAssetItems.php, ContractBOM.php, SelectProduct.php, Stocks.php and SelectCategories.php
..and its working great with multiple image types.

Update:
Just finished the work and submitted all diff files to the project.

Jan
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)