https://www.icyphoenix.com/viewtopic.php?f=35&t=6238&p=42466#p42466 ----------------------------------- Danielc Sat 08 Aug, 2009 07:13 Re: No Thumbnail After Changing Server In External Pictures ----------------------------------- I don't think that it's a good idea t change hosting... I use free hosting and so, i cannot take so much risks with my page, until i get a payment method to pay a paid hosting... I understand that this isn't a problem directly with Icy Phoenix. I understand that all of you do this in your free time, without any payment. This is why i'm investigating and trying to get it working, and i'm near from the solution (i think). I was investigating a script that works in my server, i found some curl based script, i tried to "port" to Icy Phoenix, with bad results, i did some modifications to the script, so now, i think its easier to "port".. This is the result: [code linenumbers=false] 0){ $acceptedfiletypes = array('.jpg', '.gif', '.png', '.jpeg'); $src_path[] = array(); $src_path = explode('/', $srcurl); $src_filename = $src_path[count($src_path) - 1]; $filetype = strtolower(strrchr($srcurl, '.')); if(in_array($filetype, $acceptedfiletypes)){ $default_max_size = 400; $maxsize = (isset($_GET['maxsize'])) ? $_GET['maxsize'] : $default_max_size; $maxsize = (($maxsize > 600) || ($maxsize < 30)) ? $default_max_size : $maxsize; //ECHO "DEBUG: maxsize = $maxsize
"; $tmppath = $_SERVER['DOCUMENT_ROOT'] . '/tmp/'; $thumbspath = $_SERVER['DOCUMENT_ROOT'] . '/files/thumbs/'; $urltothumbs = 'http://danielc.22web.net/files/thumbs/'; $pic_thumbnail_prefix = 'mid_' . (($maxsize != $default_max_size) ? ($maxsize . '_') : '') . md5($srcurl); $showoriginalsize = (isset($_GET['showoriginalsize'])) ? $_GET['showoriginalsize'] : 0; $filename = $pic_thumbnail_prefix . '_' . $src_filename; if(file_exists($thumbspath.$filename)){ unlink($thumbspath.$filename); //ECHO "DEBUG: Existencia de archivo previo. Eliminando.
"; } $grab = curl_init(); curl_setopt($grab, CURLOPT_URL, $srcurl); curl_setopt($grab, CURLOPT_HEADER, false); curl_setopt($grab, CURLOPT_RETURNTRANSFER, true); $grabbed = curl_exec($grab); curl_close($grab); //ECHO "DEBUG: Nombre de archivo = $filename
"; $file = fopen($tmppath.$filename, 'w'); fwrite($file, $grabbed); fclose($file); if(file_exists($tmppath.$filename)){ //ECHO "DEBUG: Archivo Subido correctamente a directorio temporal.
"; switch ($filetype){ case '.jpg': $srcimage = imagecreatefromjpeg($tmppath.$filename); //header("Content-type: image/jpeg"); break; case '.jpeg': $srcimage = imagecreatefromjpeg($tmppath.$filename); //header("Content-type: image/jpeg"); break; case '.gif': $srcimage = imagecreatefromgif($tmppath.$filename); //header("Content-type: image/gif"); break; case '.png': $srcimage = imagecreatefrompng($tmppath.$filename); //header("Content-type: image/png"); break; default: $srcimage = imagecreatefromjpeg($tmppath.$filename); //header("Content-type: image/jpeg"); } $srcimagex = imagesx($srcimage); $srcimagey = imagesy($srcimage); if($srcimagex > $maxsize || $srcimagey > $maxsize){ if($srcimagex > $srcimagey){ $ratio = $maxsize / $srcimagex; } else { $ratio = $maxsize / $srcimagey; } //next calculate the size of the thumbnail $thumbwidth = $srcimagex * $ratio; $thumbheight = $srcimagey * $ratio; } else { $thumbwidth = $srcimagex; $thumbheight = $srcimagey; } //ECHO "DEBUG: Las dimensiones calculadas de la miniatura son " . $thumbwidth . "x" . $thumbheight . "
"; if($showoriginalsize == 0){ $thumbnail = imagecreatetruecolor($thumbwidth, $thumbheight); //ECHO "DEBUG: Showoriginalsize deshabilitado
"; } else { //ECHO "DEBUG: Showoriginalsize habilitado
"; $thumbnail = imagecreatetruecolor($thumbwidth, $thumbheight + 20); $color = ImageColorAllocate($thumbnail, 0, 0, 0); imagefilledrectangle($thumbnail, 0, $thumbheight, $thumbwidth, $thumbheight + 20, $color); $color_texto = ImageColorAllocate($thumbnail, 255, 255, 255); $texto = $srcimagex . "x" . $srcimagey; //ECHO "DEBUG: texto = $texto
"; $fuente = $_SERVER['DOCUMENT_ROOT'] . '/images/fonts/denmark.ttf'; $bounds[] = array(); $bounds = imageftbbox(10,0,$fuente, $texto); $x = $bounds[0] + ($thumbwidth / 2) - ($bounds[4] / 2); $y = $bounds[1] + (20 / 2) - ($bounds[5] / 2) + $thumbheight; //ECHO "DEBUG: x = $x y = $y
"; imagettftext($thumbnail, 10, 0, $x, $y, $color_texto, $fuente, $texto); } imagecopyresampled($thumbnail, $srcimage, 0, 0, 0, 0, $thumbwidth, $thumbheight, $srcimagex, $srcimagey); header('Content-type: image/jpeg'); imagejpeg($thumbnail); imagejpeg($thumbnail, $thumbspath.$filename, 75); imagedestroy($thumbnail); unlink($tmppath.$filename); } else { //ECHO "DEBUG: No se ha subido correctamente el archivo.
"; } } else { //This file was never an image, AND WILL NEVER BE AN IMAGE! //echo 'El archivo no es una imagen.'; } } else { //ECHO "Primera condicion incumplida"; } ?>[/code] This can be tested here: http://www.danielc.22web.net/thumbcurl_auto.php To generate a thumbnail just pass the parameter srcurl with the url of the image.. You can change the size of the thumbnail with the parameter maxsize (by default 400) and you can add the original size in the bottom passing the parameter showoriginalsize=1 Example: http://www.danielc.22web.net/thumbcurl_auto.php?srcurl=http://imagenes.blogocio.net/grande/20090804_00080.jpg&maxsize=300&showoriginalsize=1 Sorry for the "echos" but i used those for testing.. Now, i need help to replace it with the image_thumbnail.php code. I will try that tomorrow, but any help is well... Thanks