Php code to create thumb not working after update

86 views Asked by At

The following php script creates a thumb and is part of an image gallery package. Though since a php update to version 5.6, the code doesn't work anymore because the appearance of 'eregi' in a dependent file.

Does anyone knows an alternative function for 'eregi'?

<?php
    include('config.inc.php');
    $C_JGALL['extentions'] = "jpg|jpeg|gif|png";

    if(is_dir('themes/' . $C_JGALL['gall_theme']) && file_exists('themes/' .$C_JGALL['gall_theme'] . '/' . $C_JGALL['gall_theme'] . '.css') && file_exists('themes/' . $C_JGALL['gall_theme'] . '/' . $C_JGALL['gall_theme'] . '.conf.php'))
    {
       include('themes/' . $C_JGALL['gall_theme'] . '/' . $C_JGALL['gall_theme'] . '.conf.php');
    }
    else
    {
       die('corrupt theme');
    }


    $MaxSize = $_GET['MaxSize'];

    switch ($_GET['src']) {
       case 'folder': 
          $src = $G_JGALL['inc_path'] . 'themes/' . $C_JGALL['gall_theme'] . '/images/folder.jpg';
          break;
       case 'question': 
          $src = $G_JGALL['inc_path'] . 'themes/' . $C_JGALL['gall_theme'] . '/images/no_image.jpg';
          break;
       default: 
          $src= $_GET['src'];
          break;
    }

    function GetExtention($filename) {
       $FileNameArray = explode('.',$filename);
       return($FileNameArray[count($FileNameArray)-1]);
    }
    $ext = GetExtention($src);

    $srcSize = getImageSize($src);

    $srcRatio = $srcSize[0]/$srcSize[1];
    $destRatio = $MaxSize/$MaxSize;

    if ($destRatio > $srcRatio) {
       $MaxSize = (($C_JGALL['gall_show_filenames'] != 'y') OR isset($_GET['view'])) ? $MaxSize : $MaxSize / 100 * 80;
       $destSize[1] = $MaxSize;
       $destSize[0] = $MaxSize*$srcRatio;
    }
    else {
       $destSize[0] = $MaxSize;
       $destSize[1] = $MaxSize/$srcRatio;
    }

    if(eregi($C_JGALL['extentions'],$ext) AND (substr($srcSize['mime'],0,5) == 'image'))
       if(eregi("jpg|jpeg",$ext)) {
          $destImage = imagecreatetruecolor($destSize[0],$destSize[1]);
          $srcImage = imagecreatefromjpeg($src);
          imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
          imagejpeg($destImage,'',80);
       } 
       elseif(eregi("gif",$ext)) {
          $destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
          $srcImage = imageCreateFromGIF($src);
          imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
          imageGIF($destImage,'',80);
       }
       elseif(eregi("png",$ext)) {
          $destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
          $srcImage = imageCreateFromPNG($src);
          imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
          imagePNG($destImage,'',80);
       } 
    else {
       die('ongeldige extentie of mime-type.');
    }

    // --> End
    ?>
1

There are 1 answers

0
Tarquin On BEST ANSWER

I would look at the PHP Documentation, as you have identified already the function has been deprecated. They do however make a recommendation to replace it;

http://php.net/manual/en/function.eregi.php

TIP eregi() is deprecated as of PHP 5.3.0. preg_match() with the i (PCRE_CASELESS) modifier is the suggested alternative.