Zubrag.com :: Forum

zubrag.com => Thumbnail Generator => Topic started by: Alecos on September 16, 2015, 04:17:45 AM



Title: Ready for PHP 7?
Post by: Alecos on September 16, 2015, 04:17:45 AM
Hello, I'm moving under php 7 and I think that your class is not ready for php 7/8. I'd like to have an updated version of the class working under php 7 and php 8.

I know that require a lot of effort but I cannot modify by myself your class since I don't know how to modify it.

Please, let's me know if it's possible. Thanks.

PS: php team removed php 4 costructors

--
Alessandro


Title: Re: Ready for PHP 7?
Post by: zubrag on September 16, 2015, 06:10:06 AM
Does it show some error? I didn't work with php for years, so don't have latest versions installed to test it. But it seems to me it should work as is.


Title: Re: Ready for PHP 7?
Post by: Alecos on September 16, 2015, 06:36:33 AM
Does it show some error? I didn't work with php for years, so don't have latest versions installed to test it. But it seems to me it should work as is.

The PHP Team removed the php 4 constructors from classes so it shouldn't work anymore in php 7 and php 8.


Title: Re: Ready for PHP 7?
Post by: zubrag on September 16, 2015, 07:32:14 AM
Watermark does not have constructor specified, so i believe it uses default constructor, which should probably also wok in php 6/7.


Title: Re: Ready for PHP 7?
Post by: Alecos on September 17, 2015, 12:57:02 AM
No watermak!!! We are talking about Thumbnail Generator!!! Hi! Please, read this RFC: https://wiki.php.net/rfc/remove_php4_constructors

Let's me know something asap, please.

Thanks.
--
Alessandro


Title: Re: Ready for PHP 7?
Post by: zubrag on September 17, 2015, 01:05:06 AM
Yes, sorry, i meant thumbnail generator.
Nothing to remove, because there is not constructor defined in thumbnail generator. It uses default (hidden, added by PHP itself) constructor.


Title: Re: Ready for PHP 7?
Post by: Alecos on September 17, 2015, 06:57:37 AM
Yes, sorry, i meant thumbnail generator.
Nothing to remove, because there is not constructor defined in thumbnail generator. It uses default (hidden, added by PHP itself) constructor.

I think that your class needs to have a constructor declared...

function __constructor() {}

otherwise under php 7 will have a notice and under php 8 will have a fatal error...


Title: Re: Ready for PHP 7?
Post by: zubrag on September 17, 2015, 08:33:20 AM
I could not find a tool to test it online and don't have php 6/7 installed to try it locally. But in case of adding empty constructor like you described, it may break code on php less than 5. So will fix when i find some place too test it on different versions.

In case it crashes for you on php 7 - please feel free to change image.class.php -> add this line
Code:
function __construct() {}

after this line
Code:
class Zubrag_image {


Title: Re: Ready for PHP 7?
Post by: Alecos on September 17, 2015, 09:45:33 AM
I could not find a tool to test it online and don't have php 6/7 installed to try it locally. But in case of adding empty constructor like you described, it may break code on php less than 5. So will fix when i find some place too test it on different versions.

In case it crashes for you on php 7 - please feel free to change image.class.php -> add this line
Code:
function __construct() {}

after this line
Code:
class Zubrag_image {

I will add this line when will be published php 7 for testing purpose. At the moment I tested this modify under php 5.6.13 and it's fine... we should see what will happen in the immediate future... thanks.


Title: Re: Ready for PHP 7?
Post by: Alecos on September 30, 2015, 08:27:14 AM
Tested on php7 rc3...

replace this:

Code:
class Zubrag_image {
    var $save_to_file = true;
    var $image_type = -1;
    var $quality = 100;
    var $max_x = 100;
    var $max_y = 100;
    var $cut_x = 0;
    var $cut_y = 0;

with this:

Code:
class Zubrag_image {
    public $save_to_file = true;
    public $image_type = -1;
    public $quality = 100;
    public $max_x = 100;
    public $max_y = 100;
    public $cut_x = 0;
    public $cut_y = 0;
    public function __construct() {
    }

other important stuff...

add to function the keyword public since in php7 function must be explicit

example...

Code:
function SaveImage(

must be

Code:
public function SaveImage(

same thing for each function in the class...


Title: Re: Ready for PHP 7? Fix image.class.php
Post by: Alecos on June 26, 2016, 10:39:44 AM
Hello! Since PHP 7.1.0 Alpha 2 changed system security check tempnam reports error when trying to download an image... the above fix works fine...

    file affected: image.class.php

    find this....

   
Code:
// generate thumb from image and save it
    public function GenerateThumbFile($from_name, $to_name) {
      // if src is URL then download file first
      $temp = false;
      if (substr($from_name,0,7) == 'http://') {
        $tmpfname = tempnam("tmp/", "TmP-");
        $temp = @fopen($tmpfname, "w");
        if ($temp) {
          @fwrite($temp, @file_get_contents($from_name)) or die("Cannot download image");
          @fclose($temp);
          $from_name = $tmpfname;
        } else {
          die("Cannot create temp file");
        }
      }

    and replace by

   
Code:
// generate thumb from image and save it
    public function GenerateThumbFile($from_name, $to_name) {
      // if src is URL then download file first
      $temp = false;
      if ((substr($from_name,0,7) == 'http://') || (substr($from_name,0,8) == 'https://')) {
        $tmpfname = tempnam(sys_get_temp_dir(), "TmP-");
        $temp = @fopen($tmpfname, "w");
        if ($temp) {
          @fwrite($temp, @file_get_contents($from_name)) or die("Cannot download image");
          @fclose($temp);
          $from_name = $tmpfname;
        } else {
          die("Cannot create temp file");
        }
      }


http://www.php.net/manual/en/function.sys-get-temp-dir.php

The goal is replacing:

$tmpfname = tempnam("tmp/", "TmP-");

by

$tmpfname = tempnam(sys_get_temp_dir(), "TmP-");

Have a nice day  ;)


Title: Re: Ready for PHP 7?
Post by: zubrag on June 30, 2016, 02:50:25 PM
Thank you for sharing this information, greatly appreciated!