Skip to content

Instantly share code, notes, and snippets.

@matthiassturm
Created May 18, 2014 22:24
Show Gist options
  • Select an option

  • Save matthiassturm/913b952b7a5d788cf561 to your computer and use it in GitHub Desktop.

Select an option

Save matthiassturm/913b952b7a5d788cf561 to your computer and use it in GitHub Desktop.

Revisions

  1. @subbo subbo revised this gist May 18, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions thumb_create.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    function thumb_create($p_photo_file, $p_thumb_file, $p_max_size, $p_quality=60)
    {
    $pic = @imagecreatefromjpeg($p_photo_file);
  2. @subbo subbo created this gist May 18, 2014.
    26 changes: 26 additions & 0 deletions thumb_create.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    function thumb_create($p_photo_file, $p_thumb_file, $p_max_size, $p_quality=60)
    {
    $pic = @imagecreatefromjpeg($p_photo_file);

    if ($pic)
    {
    $thumb = @imagecreatetruecolor($p_max_size, $p_max_size) or die ("Can't create Image!");
    $width = imagesx($pic);
    $height = imagesy($pic);

    if ($width < $height)
    {
    $twidth = $p_max_size;
    $theight = $twidth * $height / $width;
    imagecopyresampled($thumb, $pic, 0, 0, 0, ($height/2)-($width/2), $twidth, $theight, $width, $height);
    }
    else
    {
    $theight = $p_max_size;
    $twidth = $theight * $width / $height;
    imagecopyresampled($thumb, $pic, 0, 0, ($width/2)-($height/2), 0, $twidth, $theight, $width, $height);
    }

    imagejpeg($thumb, $p_thumb_file, $p_quality);
    }
    }