eT` Posted August 11, 2010 Report Posted August 11, 2010 Tamm man vajadzētu apmēram ideju, kā notiek bildes thumbnail veidošana, ja bilde NAV uz servera bet ir no URL saņemu ieseivoju cache mapē resize echo google nepalīdzēja :/ Quote
briedis Posted August 11, 2010 Report Posted August 11, 2010 saņem ar file_get_contents, vai CURL (būs ātrāk un prātīgāk) Tālāk izveido attēla resursu ar attiecīgu funkciju: http://www.php.net/manual/en/function.imagecreatefromstring.php Tālāk jau daries kā ar parastu attēlu - resaizo, saglabā... Quote
eT` Posted August 11, 2010 Author Report Posted August 11, 2010 tamm pašlaik esmu izpipējis šitik tālu: function curl($url,$name) { $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec ($ch); curl_close ($ch); $fp = fopen("cache/",'w'); //seit laikam ar rawdata vajadzētu veikt `manipulācijas` [ pārveidot lielumu utt. ] fwrite($fp, $rawdata); fclose($fp); } Quote
briedis Posted August 11, 2010 Report Posted August 11, 2010 (edited) Jā, rawdata jāliek tajā funkcijā, kas no strigna uztaisa attēla RESURSU. Edited August 11, 2010 by briedis Quote
eT` Posted August 11, 2010 Author Report Posted August 11, 2010 kaut kas laikam nestrādā kā vajag. funkcijas.php function curl($url) { $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec ($ch); curl_close ($ch); $fp = fopen("cache/",'w'); $im = imagecreatefromstring($rawdata); if ($im !== false) { header('Content-Type: image/png'); imagepng($im); imagedestroy($im); } fwrite($fp, $im); fclose($fp); } atteelo.php <div class="panel"> <?php $screen = get_post_meta($post->ID, 'screen', $single = true); curl($screen); $name = basename($screen); } ?> <img src="cache/<?php echo $name ?>" class="reflect ropacity30 rheight30" width="200" height="100" /> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> </div> Quote
marcis Posted August 11, 2010 Report Posted August 11, 2010 (edited) Šito superīgo linku atver un palasi - http://lv.php.net/imagepng Nav tev tur vajadzīgi nekādi fopen, fwrite, etc (i to līki). Un vispār tev pietiek ar pliku copy() Edited August 11, 2010 by marcis Quote
eT` Posted August 12, 2010 Author Report Posted August 12, 2010 tā man tagad izdevās laikam. $screen = get_post_meta($post->ID, 'screen', $single = true); $dest = './images/'.basename($screen); if(!file_exists($dest)) { curl($screen,$dest); crop($dest,$dest,200,100); } un abas f-jas function crop($src, $dst, $width, $height){ if(!$src = imagecreatefromstring(file_get_contents($src))) return false; $srcw = imagesx($src); $srch = imagesy($src); $tmp = imagecreatetruecolor($width, $height); // uztaisam attēlu imagefilledrectangle($tmp, 0, 0, $width, $height, imagecolorallocate($tmp, 255, 255, 255)); // balts fons // sākās visa rēķināšanas daļa if($srcw <= $width && ($srch <= $height || $height == 0)){ $nw = $srcw; $nh = $srch; }else{ $ratio = $srcw/$srch; if($height > 0 && $width/$height > $ratio){ $nw = $height*$ratio; $nh = $height; }else{ $nw = $width; $nh = $width/$ratio; } } imagecopyresampled($tmp, $src, (($width/2)-($nw/2)), (($height/2)-($nh/2)), 0, 0, $nw, $nh, $srcw, $srch); // resize if(!imagejpeg($tmp, $dst, 100)) return false; imagedestroy($tmp); return true; } function curl($url, $img) { $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); $fp = fopen($img,'x'); fwrite($fp, $rawdata); fclose($fp); } tagad viņš uztaisa 200x100px, sānos liekot baltu krāsu. f-ju tepeat atradu kaut kur. ir iespējams savādāks resize skripts, kad samazina uz noteiktiem izmēriem, bet bilde neizskatās tik saspiesta kā izmantojot <img src="" width="X" height="X" /> ? Quote
eT` Posted August 13, 2010 Author Report Posted August 13, 2010 varbūt vari iedot googles linku? vai vismaz kaut ko pateikt. :) Quote
marcis Posted August 13, 2010 Report Posted August 13, 2010 imagecopyresampled() (kuru tu, starpcitu, jau izmanto) + matemātika (līdzīga tai, kas arī tavā funkcijā ir redzama) Quote
Swear Posted August 14, 2010 Report Posted August 14, 2010 http://paste.php.lv/c0d244ce3b1a1e0c3b356938013d5a86?lang=php izdarīs visu, ko vēlējies. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.