Note that there are some explanatory texts on larger screens.

plurals
  1. POcreate thumbnail for blob with php
    primarykey
    data
    text
    <p>It is very easy to create a thumbnail as a file but I can't figure out how to use the PHP image functions to create an image and store the data inside a variable witch I can use to store the data inside a database table. </p> <p>I am new to the image functions and I do not understand their working. Are they directory orientated? So I have to create something like a tmp map for the thumbnail maker and then just use file_get_content and then remove the image. </p> <p>Or can I some how store the data of the image during the process. I have no idea!</p> <p>This is how I create thumbnails if I need to save them as a file:</p> <pre><code>//found at stackoverflow function tumbmaker($updir, $img,$MaxWe=100,$MaxHe=150){ $arr_image_details = getimagesize($img); $width = $arr_image_details[0]; $height = $arr_image_details[1]; $percent = 100; if($width &gt; $MaxWe) $percent = floor(($MaxWe * 100) / $width); if(floor(($height * $percent)/100)&gt;$MaxHe) $percent = (($MaxHe * 100) / $height); if($width &gt; $height) { $newWidth=$MaxWe; $newHeight=round(($height*$percent)/100); }else{ $newWidth=round(($width*$percent)/100); $newHeight=$MaxHe; } if ($arr_image_details[2] == 1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; } if ($arr_image_details[2] == 2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; } if ($arr_image_details[2] == 3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; } if ($imgt) { $old_image = $imgcreatefrom($img); $new_image = imagecreatetruecolor($newWidth, $newHeight); imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $imgt($new_image, $updir."_t.jpg"); return; } } </code></pre> <p>I did it with this code:</p> <pre><code>function tumbmaker($img_source,$MaxWe=100,$MaxHe=150){ $arr_image_details = getimagesize($img_source); $width = $arr_image_details[0]; $height = $arr_image_details[1]; $percent = 100; if($width &gt; $MaxWe) $percent = floor(($MaxWe * 100) / $width); if(floor(($height * $percent)/100)&gt;$MaxHe) $percent = (($MaxHe * 100) / $height); if($width &gt; $height) { $newWidth=$MaxWe; $newHeight=round(($height*$percent)/100); }else{ $newWidth=round(($width*$percent)/100); $newHeight=$MaxHe; } if ($arr_image_details[2] == 1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; } if ($arr_image_details[2] == 2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; } if ($arr_image_details[2] == 3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; } if ($imgt) { $old_image = $imgcreatefrom($img_source); $new_image = imagecreatetruecolor($newWidth, $newHeight); imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $imgt($new_image, $updir."_t.jpg"); ob_start(); $imgt($new_image); $imgData = ob_get_clean(); return $imgData; } } </code></pre> <p>Read the answer for more info</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload