function resizeImage($image, $maxHeight) { $width = ImageSx($image); $height = ImageSy($image); if ($height > $maxHeight) { $ratio = $maxHeight / $height; $x = $width * $ratio; $y = $maxHeight; } else { $x = $width; $y = $height; } $dst = ImageCreate($x, $y); ImageCopyResized($dst, $image, 0, 0, 0, 0, $x, $y, $width, $height); return $dst; }
function process() { global $CONFIG; $matches = array(); if (!preg_match("/^([0-9a-zA-Z]+)\\.png\$/", $this->file, $matches)) { error_exit("Invalid image request for {$this->file}"); } $code = $matches[1]; $basepath = trim($CONFIG['paths']['base_url'], '/') . '/image/pins'; $basefile = trim($CONFIG['paths']['file_path'], '/') . '/image/pins'; $localfile = "{$basefile}/{$code}.png"; if (file_exists($localfile)) { header("Location: http://{$_SERVER['HTTP_HOST']}/{$basepath}/{$code}.png"); } else { if (!function_exists('ImageCreateFromPNG')) { header("Location: http://{$_SERVER['HTTP_HOST']}/{$basepath}/blank-marker.png"); } else { $font = 'ttf-bitstream-vera/Vera'; $size = 6; if (strlen($code) < 3) { # Bigger image for number-only pins $size = 8; } $im = ImageCreateFromPNG("{$basefile}/blank-marker.png"); imageSaveAlpha($im, true); $tsize = ImageTTFBBox($size, 0, $font, $code); $textbg = ImageColorAllocate($im, 255, 119, 207); $black = ImageColorAllocate($im, 0, 0, 0); $dx = abs($tsize[2] - $tsize[0]); $dy = abs($tsize[5] - $tsize[3]); $x = (ImageSx($im) - $dx) / 2 + 1; $y = (ImageSy($im) - $dy) / 2; ImageTTFText($im, $size, 0, $x, $y, $black, $font, $code); header('Content-Type: image/png'); ImagePNG($im); ImagePNG($im, $localfile); ImageDestroy($im); } } exit; }
public function CreatThumb($filetype, $tsrc, $dest, $n_width, $n_height) { if ($filetype == "gif") { $im = ImageCreateFromGIF($dest); // Original picture width is stored $width = ImageSx($im); // Original picture height is stored $height = ImageSy($im); $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); ImageGIF($newimage, $tsrc); chmod("{$tsrc}", 0755); } if ($filetype == "jpg") { $im = ImageCreateFromJPEG($dest); // Original picture width is stored $width = ImageSx($im); // Original picture height is stored $height = ImageSy($im); $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); ImageJpeg($newimage, $tsrc); chmod("{$tsrc}", 0755); } if ($filetype == "png") { $im = ImageCreateFromPNG($dest); // Original picture width is stored $width = ImageSx($im); // Original picture height is stored $height = ImageSy($im); $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); imagepng($newimage, $tsrc); chmod("{$tsrc}", 0755); } }
function add_image($thread, $id, $image, $absolute_path, $db, $imagenumber) { // get max_imagesize from parameters $params = JComponentHelper::getParams('com_discussions'); $max_image_size = $params->get('maxImageSize', '209715200'); // 200 KByte default $discussions_folder = $absolute_path . "/images/discussions/"; if (!is_dir($discussions_folder)) { mkdir($discussions_folder); } $thread_folder = $absolute_path . "/images/discussions/posts/"; if (!is_dir($thread_folder)) { mkdir($thread_folder); } $image_folder = $absolute_path . "/images/discussions/posts/" . $thread . "/"; if (!is_dir($image_folder)) { mkdir($image_folder); } $image_too_big = 0; if (isset($_FILES[$image])) { if ($_FILES[$image]['size'] > $max_image_size) { $image_too_big = 1; } } if ($image_too_big == 1) { echo "<font color='#CC0000'>"; echo JText::_('COFI_UPLOADED_IMAGE_TOO_BIG'); echo "</font>"; echo "<br>"; echo "<br>"; } else { $af_size = GetImageSize($_FILES[$image]['tmp_name']); switch ($af_size[2]) { case 1: $thispicext = 'gif'; break; case 2: $thispicext = 'jpg'; break; case 3: $thispicext = 'png'; break; } // if ( $af_size[2] >= 1 && $af_size[2] <= 3) { // 1=GIF, 2=JPG or 3=PNG if ($af_size[2] >= 2 && $af_size[2] <= 3) { // 2=JPG or 3=PNG chmod($_FILES[$image]['tmp_name'], 0644); // 1. if directory ./images/USERID does not exist, create it // 2. create the subdirs for ORIGINAL, LARGE (128) and SMALL(32) if (!is_dir($image_folder . $id)) { mkdir($image_folder . $id); mkdir($image_folder . $id . "/original"); // ORIGINAL mkdir($image_folder . $id . "/large"); // LARGE (800) mkdir($image_folder . $id . "/small"); // SMALL (128) } $original_image = $image_folder . $id . "/original/" . $id . "_" . $imagenumber . "." . $thispicext; $large_image = $image_folder . $id . "/large/" . $id . "_" . $imagenumber . "." . $thispicext; $small_image = $image_folder . $id . "/small/" . $id . "_" . $imagenumber . "." . $thispicext; // copy original image to folder "original" move_uploaded_file($_FILES[$image]['tmp_name'], $original_image); // create "large" image 800px switch ($af_size[2]) { case 1: $src = ImageCreateFromGif($original_image); break; case 2: $src = ImageCreateFromJpeg($original_image); break; case 3: $src = ImageCreateFromPng($original_image); break; } $width_before = ImageSx($src); $height_before = ImageSy($src); if ($width_before >= $height_before) { $width_new = min(800, $width_before); $scale = $width_before / $height_before; $height_new = round($width_new / $scale); } else { $height_new = min(600, $height_before); $scale = $height_before / $width_before; $width_new = round($height_new / $scale); } $dst = ImageCreateTrueColor($width_new, $height_new); // GD Lib 2 ImageCopyResampled($dst, $src, 0, 0, 0, 0, $width_new, $height_new, $width_before, $height_before); switch ($af_size[2]) { case 1: ImageGIF($dst, $large_image); break; case 2: ImageJPEG($dst, $large_image); break; case 3: ImagePNG($dst, $large_image); break; } imagedestroy($dst); imagedestroy($src); // create "small" image 128px switch ($af_size[2]) { case 1: $src = ImageCreateFromGif($original_image); break; case 2: $src = ImageCreateFromJpeg($original_image); break; case 3: $src = ImageCreateFromPng($original_image); break; } $width_before = ImageSx($src); $height_before = ImageSy($src); if ($width_before >= $height_before) { $width_new = min(128, $width_before); $scale = $width_before / $height_before; $height_new = round($width_new / $scale); } else { $height_new = min(96, $height_before); $scale = $height_before / $width_before; $width_new = round($height_new / $scale); } $dst = ImageCreateTrueColor($width_new, $height_new); // GD Lib 2 ImageCopyResampled($dst, $src, 0, 0, 0, 0, $width_new, $height_new, $width_before, $height_before); switch ($af_size[2]) { case 1: ImageGIF($dst, $small_image); break; case 2: ImageJPEG($dst, $small_image); break; case 3: ImagePNG($dst, $small_image); break; } imagedestroy($dst); imagedestroy($src); // DB update $sql = "UPDATE #__discussions_messages SET " . $image . "='" . $id . "_" . $imagenumber . "." . $thispicext . "' WHERE id=" . $id; $db->setQuery($sql); if ($db->getErrorNum()) { echo $db->stderr(); } else { $db->query(); } } } }
function create_image() { // To send to print sizes, per original asset. $sizes['print']['w'] = 5315; $sizes['print']['h'] = 3780; // Preview size $sizes['preview']['w'] = 786; $sizes['preview']['h'] = 588; // Create print size document, so all additional components are in correct position $printCanvas = imagecreatetruecolor($sizes['print']['w'], $sizes['print']['h']); // Colour references, white for foil blocked text (won't be on final print) and black for date and names. $colours['white'] = imagecolorallocate($printCanvas, 255, 255, 255); $colours['black'] = imagecolorallocate($printCanvas, 0, 0, 0); // Initially start with black image imagefill($printCanvas, 0, 0, $colours['black']); // Load in print asset $printSrc = imagecreatefromjpeg('final.jpg'); // Add print asset to current canvas imagecopymerge($printCanvas, $printSrc, 0, 0, 0, 0, $sizes['print']['w'], $sizes['print']['h'], 100); // Once merged, destroy source image imagedestroy($printSrc); // Add in foil blocked text if in preview mode if (isset($_GET['preview'])) { imagettftext($printCanvas, 300, 0, 1865, 1225, $colours['white'], '28DaysLater.ttf', 'Established'); imagettftext($printCanvas, 200, 0, 2418, 2325, $colours['white'], '28DaysLater.ttf', isset($_GET['title']) ? $_GET['title'] : 'Title here'); } // If we have a valid information, set it, else just change to "Data here" if (isset($_GET['date'])) { $date = $_GET['date']; } else { $date = 'Date here'; } if (isset($_GET['names'])) { $names = $_GET['names']; } else { $names = 'Names here'; } if (isset($_GET['image'])) { $image = $_GET['image']; } else { $image = 'http://lorempixel.com/1280/1120/people/Sample Image'; } // Print names onto the canvas imagettftext($printCanvas, 120, 0, 2418, 2490, $colours['black'], 'Rockwell.ttf', $names); // Print date onto the canvas, make the end of it match up to the end of "Established" above $type_space = imagettfbbox(120, 0, 'Rockwell.ttf', $date); imagettftext($printCanvas, 120, 0, 3750 - $type_space[4], 1360, $colours['black'], 'Rockwell.ttf', $date); // Ascertain if this is a external image, and if not, add on the current server address if (substr($image, 0, 4) != 'http') { $image = 'http://' . $_SERVER['SERVER_NAME'] . '/' . $image; } // Create image using the supplied image, and log the size $imageSrc = imagecreatefromjpeg($image); $sizes['image']['w'] = ImageSx($imageSrc); $sizes['image']['h'] = ImageSy($imageSrc); if (1280 - $sizes['image']['w'] < 1120 - $sizes['image']['h']) { $s = 1120 / $sizes['image']['h']; $sizes['imageSrc']['w'] = round($sizes['image']['w'] * $s); $sizes['imageSrc']['h'] = round($sizes['image']['h'] * $s); } else { $s = 1280 / $sizes['image']['w']; $sizes['imageSrc']['w'] = round($sizes['image']['w'] * $s); $sizes['imageSrc']['h'] = round($sizes['image']['h'] * $s); } // Create canvas for the supplied image to sit in $imageCanvas = ImageCreateTrueColor(1280, 1120); // Adjust the image position if the width or height is too big, to place the image in the centre if ($sizes['imageSrc']['w'] > 1280) { $newX = -(($sizes['imageSrc']['w'] - 1280) / 2); } else { $newX = 0; } if ($sizes['imageSrc']['h'] > 1120) { $newY = -(($sizes['imageSrc']['h'] - 1120) / 2); } else { $newY = 0; } // Copy image source onto the canvas imagecopyresized($imageCanvas, $imageSrc, $newX, $newY, 0, 0, $sizes['imageSrc']['w'], $sizes['imageSrc']['h'], $sizes['image']['w'], $sizes['image']['h']); // Prep the image for rotation $canvasTrans = imagecolorallocatealpha($imageCanvas, 0, 0, 0, 127); // Rotate image, and log new size $imageCanvas = imagerotate($imageCanvas, 5, $canvasTrans); $sizes['rotated-image']['w'] = ImageSx($imageCanvas); $sizes['rotated-image']['h'] = ImageSy($imageCanvas); // Add the rotated supplied image onto the print canvas ImageCopyResampled($printCanvas, $imageCanvas, 870, 1650, 0, 0, $sizes['rotated-image']['w'], $sizes['rotated-image']['h'], $sizes['rotated-image']['w'], $sizes['rotated-image']['h']); // Once copied, destroy image canvas, and source image imagedestroy($imageSrc); imagedestroy($imageCanvas); // If generating preview, adjust size of output if (isset($_GET['preview'])) { // Calculate how the aspect ratio should be calculated if ($sizes['preview']['w'] - $sizes['print']['w'] > $sizes['preview']['h'] - $sizes['print']['h']) { $s = $sizes['preview']['h'] / $sizes['print']['h']; $nw = round($sizes['print']['w'] * $s); $nh = round($sizes['print']['h'] * $s); } else { $s = $sizes['preview']['w'] / $sizes['print']['w']; $nw = round($sizes['print']['w'] * $s); $nh = round($sizes['print']['h'] * $s); } // Create canvas to match size of desired preview $previewCanvas = imagecreatetruecolor($sizes['preview']['w'], $sizes['preview']['h']); // Copy the whole print canvas onto the preview canvas at the reduced size // This also repositions the canvas, as we don't need crop marks in the preview. ImageCopyResampled($previewCanvas, $printCanvas, -110, -56, 0, 0, $nw + 220, $nh + 139, $sizes['print']['w'], $sizes['print']['h']); // Output the preview canvas imagepng($previewCanvas); // Destroy the preview and print canvas, as now no longer needed. imagedestroy($previewCanvas); imagedestroy($printCanvas); } else { // Output the print canvas imagepng($printCanvas); // Destroy the preview and print canvas, as now no longer needed. imagedestroy($printCanvas); } }
} else { // return the finished image as PNG if (!headers_sent()) { Safe::header("Content-type: image/png"); } // enable 30-minute caching (30*60 = 1800), even through https, to help IE6 on download http::expire(1800); // strong validator $etag = '"' . md5($item['geo_place_name'] . $item['longitude'] . $item['latitude']) . '"'; // manage web cache if (http::validate(NULL, $etag)) { return; } // load the main image $image = ImageCreateFromJpeg($context['path_to_root'] . 'locations/images/earth_310.jpg'); $width = ImageSx($image); $height = ImageSy($image); // ensure we have split coordinates if (!$item['latitude'] || !$item['longitude']) { list($item['latitude'], $item['longitude']) = preg_split('/[\\s,;]+/', $item['geo_position']); } // scale coordinates $x = round(($item['longitude'] + 180) * ($width / 360)); $y = round(($item['latitude'] * -1 + 90) * ($height / 180)); // mark the point on the map using a red 4 pixel rectangle $red = ImageColorAllocate($image, 255, 0, 0); ImageFilledRectangle($image, $x - 2, $y - 2, $x + 2, $y + 2, $red); // actual transmission except on a HEAD request if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') { ImagePng($image); }
$fn2 = mb_convert_encoding($fn, $file_char_code, 'auto'); $path_parts = pathinfo($fn2); //echo $path_parts['extension']; if ($path_parts['extension'] == "JPG" || $path_parts['extension'] == "jpg") { //JPEGファイルを読み込む $image = ImageCreateFromJPEG($fn2); } else { if ($path_parts['extension'] == "png") { //$fn2=mb_convert_encoding($fn,$file_char_code,'auto'); $image = imagecreatefrompng($fn2); //imagecreatefromstring(file_get_contents($fn)); } } //echo $info; // 元画像のファイルサイズを取得 $original_width = ImageSx($image); $original_height = ImageSy($image); //元画像の比率を計算し、高さを設定 $proportion = $original_width / $original_height; $height = $width / $proportion; //高さが幅より大きい場合は、高さを幅に合わせ、横幅を縮小 if ($proportion < 1) { $height = $width; $width = $width * $proportion; } $new_image = ImageCreateTrueColor($width, $height); // 画像作成 // 元画像から再サンプリング ImageCopyResampled($new_image, $image, 0, 0, 0, 0, $width, $height, $original_width, $original_height); // 保存 ImageJpeg($new_image, '/var/www/lifelog/DATA/boost/s/' . $newstr, 80);
function update_produk() { $this->load->library('form_validation'); $this->form_validation->set_rules('nama', 'nama', 'trim|required'); $this->form_validation->set_rules('harga', 'harga', 'trim|required'); $this->form_validation->set_rules('stok', 'stok', 'trim|required'); $this->form_validation->set_rules('dibeli', 'dibeli', 'trim|required'); $this->form_validation->set_rules('username', 'Username', 'trim|required'); $this->form_validation->set_rules('deskripsi', 'deskripsi', 'trim|required'); $this->form_validation->set_error_delimiters('<span style="color:#FF00000">' . '</span>'); $kategori = mysql_real_escape_string($this->input->post('kategori')); $nama = mysql_real_escape_string($this->input->post('nama')); $harga = mysql_real_escape_string($this->input->post('harga')); $stok = mysql_real_escape_string($this->input->post('stok')); $dibeli = mysql_real_escape_string($this->input->post('dibeli')); $deskripsi = mysql_real_escape_string($this->input->post('deskripsi')); $tipe = mysql_real_escape_string($this->input->post('tipe')); $kode = $this->input->post('id'); $gbr = $this->input->post('gbr'); if (empty($_FILES['imagefile']['name'])) { $this->produk_model->jalankan_query_manual("update produk set id_kategori='" . $kategori . "', nama_produk='" . $nama . "', harga='" . $harga . "', stok='" . $stok . "', dibeli='" . $dibeli . "', deskripsi='" . $deskripsi . "' where id_produk='" . $kode . "'"); echo "<meta http-equiv='refresh' content='0; url=" . site_url() . "/produk'>"; } else { if ($_FILES['imagefile']['type'] == "image/jpeg") { $ori_src = "assets/produk/imgoriginal/" . strtolower(str_replace(' ', '_', $_FILES['imagefile']['name'])); if (move_uploaded_file($_FILES['imagefile']['tmp_name'], $ori_src)) { chmod("{$ori_src}", 0777); } else { echo "Gagal melakukan proses upload file."; exit; } $thumb_src = "assets/produk/" . strtolower(str_replace(' ', '_', $_FILES['imagefile']['name'])); $n_width = 150; $n_height = 150; if ($_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/png" || $_FILES['imagefile']['type'] == "image/gif") { $im = @ImageCreateFromJPEG($ori_src) or $im = @ImageCreateFromPNG($ori_src) or $im = @ImageCreateFromGIF($ori_src) or $im = false; // If image is not JPEG, PNG, or GIF //$im=ImageCreateFromJPEG($ori_src); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored if ($n_height == 0 && $n_width == 0) { $n_height = $height; $n_width = $width; } if (!$im) { echo '<p>Gagal membuat thumnail</p>'; exit; } else { $newimage = @imagecreatetruecolor($n_width, $n_height); @imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); @ImageJpeg($newimage, $thumb_src); chmod("{$thumb_src}", 0777); } } $this->produk_model->jalankan_query_manual("update produk set id_kategori='" . $kategori . "', nama_produk='" . $nama . "', harga='" . $harga . "', stok='" . $stok . "', dibeli='" . $dibeli . "', gbr_kecil='" . $_FILES['imagefile']['name'] . "', gbr_besar='" . $_FILES['imagefile']['name'] . "', deskripsi='" . $deskripsi . "' where id_produk='" . $kode . "'"); $file_kcl = './assets/produk/' . $gbr; $file_bsr = './assets/produk/imgoriginal/' . $gbr; unlink($file_kcl); unlink($file_bsr); echo "<meta http-equiv='refresh' content='0; url=" . site_url() . "/produk'>"; } else { echo "Mohon upload foto yang berjenis gambar!"; } } }
} $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); ImageJPEG($newimage, $tsrc); } // $to = "*****@*****.**"; // // $subject = "***Skippy Alert***"; // // $body = "Somebody just used Skippy the Shoe Finder!"; // // $headers = "From: noreply@skippysearch.com\n"; // // mail($to,$subject,$body,$headers); // // Color Select // $sample = 100; $pig = 32; // Get picture height and width // $im = imagecreatefromjpeg($tsrc); $width = ImageSx($im); $height = ImageSy($im); $winc = round($width / sqrt($sample / ($height / $width))); $hinc = round($height / sqrt($sample / ($width / $height))); // Scan the picture // $tick = 0; $winc = 3; $hinc = 3; $topx = $width * 0.4; $bottomx = $width * 0.6; $topy = $height * 0.4; $bottomy = $height * 0.6; for ($x = $topx; $x < $bottomx; $x += $winc) { for ($y = $topy; $y < $bottomy; $y += $hinc) { $tick = $tick + 1; $samp[$tick] = ImageColorAt($im, $x, $y);
// Draw a border in destination image ImageRectangle($imageOut, 0, 0, $outX - 1, $outY - 1, ImageColorAllocate($imageOut, 0, 0, 0)); // Do the work $nextX = BORDER_LEFT; $nextY = BORDER_TOP; foreach ($imageKeys as $imageKey) { // Fetch the image print " Fetch image '{$imageKey}'\n"; $image = $s3->get_object(BOOK_BUCKET, $imageKey); // Convert it to GD format $imageBits = ImageCreateFromString($image->body); // Copy it to proper spot in the destination print " Render image at {$nextX}, {$nextY}\n"; ImageCopy($imageOut, $imageBits, $nextX, $nextY, 0, 0, ImageSx($imageBits), ImageSy($imageBits)); // Draw a border around it ImageRectangle($imageOut, $nextX, $nextY, $nextX + ImageSx($imageBits), $nextY + ImageSy($imageBits), ImageColorAllocate($imageOut, 0, 0, 0)); // Update position for next image $nextX += THUMB_SIZE + GAP_SIZE; if ($nextX + THUMB_SIZE > $outX) { $nextX = BORDER_LEFT; $nextY += THUMB_SIZE + GAP_SIZE; } } // Get the bits of the destination image $imageFileOut = tempnam('/tmp', 'aws') . '.png'; ImagePNG($imageOut, $imageFileOut, 0); $imageBitsOut = file_get_contents($imageFileOut); unlink($imageFileOut); // Store the final image in S3 $key = 'page_image_' . md5($pageTitle) . '.png'; if (uploadObject($s3, BOOK_BUCKET, $key, $imageBitsOut, AmazonS3::ACL_PUBLIC)) {
function addwatermark($newimage, $wm_loc, $wm_use, $wm_file, $wm_dir) { global $roster, $addon; $widthtn = ImageSx($newimage); // thumb width is stored $heightn = ImageSy($newimage); // thumb width is stored $wm = $addon['dir'] . $wm_dir . '/' . $wm_file; if (file_exists($wm)) { $blah = getimagesize($wm); $type = $blah['mime']; $widthwm = $blah[0]; $heightwm = $blah[1]; # this is where we determin where to place the water mark we ar gona # allways ass a 5pix buffer incase the image uses the hole image size # 1 = top left - 2 = top right - 3 = bottom left - 4 = bottom right if ($wm_loc == 1) { $lox = 8; $loy = 8; } if ($wm_loc == 2) { $lox = $widthtn - $widthwm - 8; $loy = 8; } if ($wm_loc == 3) { $lox = 8; $loy = $heightn - $heightwm - 8; } if ($wm_loc == 4) { $lox = $widthtn - $widthwm - 8; $loy = $heightn - $heightwm - 8; } $this->combineImage($newimage, $wm, __LINE__, $lox, $loy); } else { $this->setMessage("watermark " . $wm . " does not exist"); } return $newimage; }
/** * resize image */ function resizeImage($path,$file,$filename,$width,$height,$format) { /* use this example for reference path: C:/xampp/htdocs/vl/onlinefiles/uploads/_usericons/84/, file: C:/xampp/htdocs/vl/onlinefiles/uploads/_usericons/84/bmwx62.jpg, filename: bmwx62.jpg, width: 640, height: 480, dir: , format: jpg */ //thumbnail settings $tmb_src=0; $tmb_src=$file; //thumbnail creation $image=0; $imagewidth=0; $imageheight=0; switch($format) { case GIF: case gif: $image=ImageCreateFromGIF($tmb_src); break; case JPEG: case JPG: case jpeg: case jpg: $image=ImageCreateFromJPEG($tmb_src); break; case PNG: $image=ImageCreateFromPNG($tmb_src); break; } //parsed dimensions $tmb_width=0; $tmb_height=0; //default dimensions $imagewidth=ImageSx($image); $imageheight=ImageSy($image); $newimage=0; //do the neccessary resizing on condition that ... if($imagewidth>$width || $imageheight>$height) { if ($imagewidth > $imageheight) { $tmb_width=$width; $tmb_height=$imageheight*($width/$imagewidth); } else if($imageheight > $imagewidth) { $tmb_height=$height; $tmb_width=$imagewidth*($height/$imageheight); } else { $tmb_width=$width; $tmb_height=$height; } } else { $tmb_width=$imagewidth; $tmb_height=$imageheight; } $newimage=imagecreatetruecolor($tmb_width,$tmb_height); imageCopyResized($newimage,$image,0,0,0,0,$tmb_width,$tmb_height,$imagewidth,$imageheight); switch($format) { case GIF: case gif: if(function_exists("imagegif")) { //Header("Content-type: image/gif"); ImageGIF($newimage,$path.$filename); chmod($path.$filename,0755); } else if(function_exists("imagejpeg")) { //Header("Content-type: image/jpeg"); ImageJPEG($newimage,$path.$filename); chmod($path.$filename,0755); } break; case JPEG: case JPG: case jpeg: case jpg: if(function_exists("imagejpeg")) { //Header("Content-type: image/jpeg"); ImageJPEG($newimage,$path.$filename); chmod($path.$filename,0755); } break; case PNG: case png: if(function_exists("imagepng")) { //Header("Content-type: image/png"); ImagePNG($newimage,$path.$filename); chmod($path.$filename,0755); } break; } }
function update_produk() { if ($this->session->userdata('masuk')) { $kategori = mysql_real_escape_string($this->input->post('kategori')); $nama = mysql_real_escape_string($this->input->post('nama')); $harga = mysql_real_escape_string($this->input->post('harga')); $stok = mysql_real_escape_string($this->input->post('stok')); $dibeli = mysql_real_escape_string($this->input->post('dibeli')); $deskripsi = mysql_real_escape_string($this->input->post('deskripsi')); $tipe = mysql_real_escape_string($this->input->post('tipe')); $kode = $this->input->post('id'); $gbr = $this->input->post('gbr'); $gbr2 = $this->input->post('gbr2'); if (empty($_FILES['imagefile']['name'])) { //gambar 2 edit mulai if (empty($_FILES['imagefile2']['name'])) { $this->m_awal->jalankan_query_manual("update tbl_produk set id_kategori='" . $kategori . "', nama_produk='" . $nama . "', harga='" . $harga . "', \n\t\t\t\t\tstok='" . $stok . "', dibeli='" . $dibeli . "', deskripsi='" . $deskripsi . "', tipe_produk='" . $tipe . "' where kode_produk='" . $kode . "'"); echo "<meta http-equiv='refresh' content='0; url=" . base_url() . "index.php/admin'>"; } else { if ($_FILES['imagefile2']['type'] == "image/jpeg") { $ori_src = "asset/produk/imgoriginal/" . strtolower(str_replace(' ', '_', $_FILES['imagefile2']['name'])); if (move_uploaded_file($_FILES['imagefile2']['tmp_name'], $ori_src)) { chmod("{$ori_src}", 0777); } else { echo "Gagal melakukan proses upload file."; exit; } $thumb_src = "asset/produk/" . strtolower(str_replace(' ', '_', $_FILES['imagefile2']['name'])); $n_width = 150; $n_height = 150; if ($_FILES['imagefile2']['type'] == "image/jpeg" || $_FILES['imagefile2']['type'] == "image/png" || $_FILES['imagefile2']['type'] == "image/gif") { $im = @ImageCreateFromJPEG($ori_src) or $im = @ImageCreateFromPNG($ori_src) or $im = @ImageCreateFromGIF($ori_src) or $im = false; // If image is not JPEG, PNG, or GIF //$im=ImageCreateFromJPEG($ori_src); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored if ($n_height == 0 && $n_width == 0) { $n_height = $height; $n_width = $width; } if (!$im) { echo '<p>Gagal membuat thumnail</p>'; exit; } else { $newimage = @imagecreatetruecolor($n_width, $n_height); @imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); @ImageJpeg($newimage, $thumb_src); chmod("{$thumb_src}", 0777); } } $this->m_awal->jalankan_query_manual("update tbl_produk set id_kategori='" . $kategori . "', nama_produk='" . $nama . "', harga='" . $harga . "', \n\t\t\t\t\t\tstok='" . $stok . "', dibeli='" . $dibeli . "', gbr_kecil2='" . $_FILES['imagefile2']['name'] . "', gbr_besar2='" . $_FILES['imagefile2']['name'] . "', \n\t\t\t\t\t\tdeskripsi='" . $deskripsi . "', tipe_produk='" . $tipe . "' where kode_produk='" . $kode . "'"); $file_kcl = './asset/produk/' . $gbr2; $file_bsr = './asset/produk/imgoriginal/' . $gbr2; unlink($file_kcl); unlink($file_bsr); echo "<meta http-equiv='refresh' content='0; url=" . base_url() . "index.php/admin'>"; } else { echo "Hayooo,,,mau upload file apaan tuh...??? Upload yang berjenis gambar aja mas brow, gak usah macam-macam...!!! OKOK"; } //gambar 2 edit selssai } } else { if (empty($_FILES['imagefile2']['name'])) { if ($_FILES['imagefile']['type'] == "image/jpeg") { $ori_src = "asset/produk/imgoriginal/" . strtolower(str_replace(' ', '_', $_FILES['imagefile']['name'])); if (move_uploaded_file($_FILES['imagefile']['tmp_name'], $ori_src)) { chmod("{$ori_src}", 0777); } else { echo "Gagal melakukan proses upload file."; exit; } $thumb_src = "asset/produk/" . strtolower(str_replace(' ', '_', $_FILES['imagefile']['name'])); $n_width = 150; $n_height = 150; if ($_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/png" || $_FILES['imagefile']['type'] == "image/gif") { $im = @ImageCreateFromJPEG($ori_src) or $im = @ImageCreateFromPNG($ori_src) or $im = @ImageCreateFromGIF($ori_src) or $im = false; // If image is not JPEG, PNG, or GIF //$im=ImageCreateFromJPEG($ori_src); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored if ($n_height == 0 && $n_width == 0) { $n_height = $height; $n_width = $width; } if (!$im) { echo '<p>Gagal membuat thumnail</p>'; exit; } else { $newimage = @imagecreatetruecolor($n_width, $n_height); @imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); @ImageJpeg($newimage, $thumb_src); chmod("{$thumb_src}", 0777); } } $this->m_awal->jalankan_query_manual("update tbl_produk set id_kategori='" . $kategori . "', nama_produk='" . $nama . "', harga='" . $harga . "', \n\t\t\t\t\t\tstok='" . $stok . "', dibeli='" . $dibeli . "', gbr_kecil='" . $_FILES['imagefile']['name'] . "', gbr_besar='" . $_FILES['imagefile']['name'] . "', \n\t\t\t\t\t\tdeskripsi='" . $deskripsi . "', tipe_produk='" . $tipe . "' where kode_produk='" . $kode . "'"); $file_kcl = './asset/produk/' . $gbr; $file_bsr = './asset/produk/imgoriginal/' . $gbr; unlink($file_kcl); unlink($file_bsr); echo "<meta http-equiv='refresh' content='0; url=" . base_url() . "index.php/admin'>"; } else { echo "Hayooo,,,mau upload file apaan tuh...??? Upload yang berjenis gambar aja mas brow, gak usah macam-macam...!!! OKOK"; } } else { if ($_FILES['imagefile2']['type'] == "image/jpeg") { $ori_src = "asset/produk/imgoriginal/" . strtolower(str_replace(' ', '_', $_FILES['imagefile2']['name'])); if (move_uploaded_file($_FILES['imagefile2']['tmp_name'], $ori_src)) { chmod("{$ori_src}", 0777); } else { echo "Gagal melakukan proses upload file."; exit; } $thumb_src = "asset/produk/" . strtolower(str_replace(' ', '_', $_FILES['imagefile2']['name'])); $n_width = 150; $n_height = 150; if ($_FILES['imagefile2']['type'] == "image/jpeg" || $_FILES['imagefile2']['type'] == "image/png" || $_FILES['imagefile2']['type'] == "image/gif") { $im = @ImageCreateFromJPEG($ori_src) or $im = @ImageCreateFromPNG($ori_src) or $im = @ImageCreateFromGIF($ori_src) or $im = false; // If image is not JPEG, PNG, or GIF //$im=ImageCreateFromJPEG($ori_src); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored if ($n_height == 0 && $n_width == 0) { $n_height = $height; $n_width = $width; } if (!$im) { echo '<p>Gagal membuat thumnail</p>'; exit; } else { $newimage = @imagecreatetruecolor($n_width, $n_height); @imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); @ImageJpeg($newimage, $thumb_src); chmod("{$thumb_src}", 0777); } } $this->m_awal->jalankan_query_manual("update tbl_produk set id_kategori='" . $kategori . "', nama_produk='" . $nama . "', harga='" . $harga . "', \n\t\t\t\t\t\tstok='" . $stok . "', dibeli='" . $dibeli . "', \n\t\t\t\t\t\tgbr_kecil2='" . $_FILES['imagefile2']['name'] . "', gbr_besar2='" . $_FILES['imagefile2']['name'] . "', \n\t\t\t\t\t\tgbr_kecil='" . $_FILES['imagefile']['name'] . "', gbr_besar='" . $_FILES['imagefile']['name'] . "',\n\t\t\t\t\t\tdeskripsi='" . $deskripsi . "', tipe_produk='" . $tipe . "' where kode_produk='" . $kode . "'"); $file_kcl = './asset/produk/' . $gbr; $file_bsr = './asset/produk/imgoriginal/' . $gbr; unlink($file_kcl); unlink($file_bsr); $file_kcl2 = './asset/produk/' . $gbr2; $file_bsr2 = './asset/produk/imgoriginal/' . $gbr2; unlink($file_kcl2); unlink($file_bsr2); echo "<meta http-equiv='refresh' content='0; url=" . base_url() . "index.php/admin'>"; } else { echo "Hayooo,,,mau upload file apaan tuh...??? Upload yang berjenis gambar aja mas brow, gak usah macam-macam...!!! OKOK"; } //gambar 2 edit selssai } } } else { if ($_POST) { echo $this->m_login->ceklogin(); redirect(base_url('login')); } else { $this->load->view('verifikasi'); } } }
$XML = To_XML_String($Codes); if (Is_Error($XML)) { return ERROR | @Trigger_Error(500); } #------------------------------------------------------------------------------- $Tmp = System_Element('tmp'); if (Is_Error($Tmp)) { return ERROR | @Trigger_Error(500); } #------------------------------------------------------------------------------- $IsWrite = IO_Write(SPrintF('%s/protect.xml', $Tmp), $XML, TRUE); if (Is_Error($IsWrite)) { return ERROR | @Trigger_Error(500); } #------------------------------------------------------------------------------- $Path = Styles_Element('Images/ProtectBg.png'); if (Is_Error($Path)) { return ERROR | @Trigger_Error(500); } #------------------------------------------------------------------------------- $Im = ImageCreateFromPng($Path); #------------------------------------------------------------------------------- $Color = ImageColorAllocate($Im, 0, 0, 0); #------------------------------------------------------------------------------- $Px = (ImageSx($Im) - 8.5 * StrLen($Secret)) / 2; #------------------------------------------------------------------------------- ImageString($Im, 5, $Px, 9, $Secret, $Color); #------------------------------------------------------------------------------- Header('Content-Type: image/png'); ImagePng($Im); #-------------------------------------------------------------------------------
/** *生成图片缩略图(保持比例) * @access private * @param string $im 图片文件名,可以包括路径名 * @return string $maxwidth 新图片的宽度 * @return string $maxheight 新图片的高度 * @return string $name 新图片文件名 */ function ResizeImageT($im, $maxwidth, $maxheight, $name = "") { if (!file_exists($im)) { return false; } if (!$name) { $path_parts = pathinfo($im); if (empty($name)) { $name = $path_parts['dirname'] . '/' . $path_parts['filename'] . "({$maxwidth}x{$maxheight})." . $path_parts['extension']; } } if ($maxwidth == 0 || $maxheight == 0) { return $name; } $im_type = $this->get_type($im); $im = $this->createImage($im_type, $im); $width = ImageSx($im); $height = ImageSy($im); if ($maxwidth && $width > $maxwidth || $maxheight && $height > $maxheight) { if ($maxwidth && $width > $maxwidth) { $widthratio = $maxwidth / $width; $RESIZEWIDTH = true; } if ($maxheight && $height > $maxheight) { $heightratio = $maxheight / $height; $RESIZEHEIGHT = true; } if ($RESIZEWIDTH && $RESIZEHEIGHT) { if ($widthratio < $heightratio) { $ratio = $widthratio; } else { $ratio = $heightratio; } } elseif ($RESIZEWIDTH) { $ratio = $widthratio; } elseif ($RESIZEHEIGHT) { $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if (function_exists("imagecopyresampled")) { $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } else { $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg($newim, $name); ImageDestroy($newim); } else { ImageJpeg($im, $name); } return $name; }
$size = $_FILES['FileToUpload']['size']; //Get the Size of the File if (count($aErrors) == 0 && $size > $sizeBytes) { $aErrors[] = "The File you tried to upload is <b>" . $size . "</b>K. Maximum file size: <b>" . $sizeBytes . "</b>K. Please upload a smaller file."; } if (count($aErrors) == 0 && !checkFileType($file_types, $_FILES['FileToUpload']['type'])) { //Make sure file is of allowable file types $aErrors[] = "File you tried to upload is <b>" . $_FILES['FileToUpload']['type'] . "</b>. This file type is not currently allowed."; } //move_filetoupload_file('filename','destination') Moves file to directory if (count($aErrors) == 0 && move_uploaded_file($_FILES['FileToUpload']['tmp_name'], $uploadFolder . $FileName)) { if ($createThumb == "TRUE") { //create thumbnail in same folder, add thumbSuffix $tempImage = ImageCreateFromJPEG($uploadFolder . $FileName); //copy to temporary image $width = ImageSx($tempImage); // Original picture width $height = ImageSy($tempImage); // Original picture height $thumbHeight = floor($height * ($thumbWidth / $width)); // calculate proper thumbnail height $newimage = imagecreatetruecolor($thumbWidth, $thumbHeight); //create new blank image imageCopyResampled($newimage, $tempImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height); //copy to thumb ImageJpeg($newimage, $uploadFolder . $imagePrefix . $myID . $thumbSuffix . $extension); //create thumbnail in same directory } //append timestamp to qstring to print temporary reload() message $mySeconds = time(); //redirect to item page so new file can be seen
$size_down = false; } $key = array_search($pref, $music_position); if ($key == FALSE) { continue; } else { $stamp_size = $img_music_size; $key1 = strstr($key, '_', true); $key2 = str_replace($key1 . "_", "", $key); if ($pref == "23_0") { $img_stamp = imagecreatefrompng('img/stamp_c.png'); } else { $img_stamp = imagecreatefrompng('img/stamp.png'); } // 縮小処理 $width = ImageSx($img_stamp); $height = ImageSy($img_stamp); $resize = ImageCreateTrueColor($stamp_size, $stamp_size); imagealphablending($resize, false); imagesavealpha($resize, true); ImageCopyResampled($resize, $img_stamp, 0, 0, 0, 0, $stamp_size, $stamp_size, $width, $height); imagecopymerge($img, $resize, $key1, $key2, 0, 0, $stamp_size, $stamp_size, 55); } } // foreachおわり // 合計曲数を入れる ImageTTFText($img, 20, 0, 160, 280, $black, $font, $debut . " / " . $music_max / 4); ImageTTFText($img, 20, 0, 160, 311, $black, $font, $regular . " / " . $music_max / 4); ImageTTFText($img, 20, 0, 160, 342, $black, $font, $pro . " / " . $music_max / 4); ImageTTFText($img, 20, 0, 160, 373, $black, $font, $master . " / " . $music_max / 4); // 全曲総合処理
function getPos($sourcefile_width, $sourcefile_height, $pos, $wm_image = "") { if ($wm_image) { $insertfile_width = ImageSx($wm_image); $insertfile_height = ImageSy($wm_image); } else { $lineCount = explode("\n", $this->wm_text); $fontSize = imagettfbbox($this->wm_text_size, $this->wm_text_angle, $this->wm_text_font, $this->wm_text); $insertfile_width = $fontSize[2] - $fontSize[0]; $insertfile_height = count($lineCount) * ($fontSize[1] - $fontSize[7]); } switch ($pos) { case 0: $dest_x = $sourcefile_width / 2 - $insertfile_width / 2; $dest_y = $sourcefile_height / 2 - $insertfile_height / 2; break; case 1: $dest_x = 0; if ($this->wm_text) { $dest_y = $insertfile_height; } else { $dest_y = 0; } break; case 2: $dest_x = $sourcefile_width - $insertfile_width; if ($this->wm_text) { $dest_y = $insertfile_height; } else { $dest_y = 0; } break; case 3: $dest_x = $sourcefile_width - $insertfile_width; $dest_y = $sourcefile_height - $insertfile_height; break; case 4: $dest_x = 0; $dest_y = $sourcefile_height - $insertfile_height; break; case 5: $dest_x = ($sourcefile_width - $insertfile_width) / 2; if ($this->wm_text) { $dest_y = $insertfile_height; } else { $dest_y = 0; } break; case 6: $dest_x = $sourcefile_width - $insertfile_width; $dest_y = $sourcefile_height / 2 - $insertfile_height / 2; break; case 7: $dest_x = ($sourcefile_width - $insertfile_width) / 2; $dest_y = $sourcefile_height - $insertfile_height; break; case 8: $dest_x = 0; $dest_y = $sourcefile_height / 2 - $insertfile_height / 2; break; default: $dest_x = $sourcefile_width - $insertfile_width; $dest_y = $sourcefile_height - $insertfile_height; break; } return array("dest_x" => $dest_x, "dest_y" => $dest_y); }
/** * @package Codingfish Discussions * @subpackage com_discussions * @copyright Copyright (C) 2010 Codingfish (Achim Fischer). All rights reserved. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html> * @link http://www.codingfish.com */ function add_image($user_id, $image, $absolute_path, $db) { $af_dir_ads = $absolute_path . "/images/discussions/users/"; $max_image_size = 209715200; // 200 KByte ? $discussions_folder = $absolute_path . "/images/discussions/"; if (!is_dir($discussions_folder)) { mkdir($discussions_folder); } $users_folder = $absolute_path . "/images/discussions/users/"; if (!is_dir($users_folder)) { mkdir($users_folder); } $image_too_big = 0; if (isset($_FILES['avatar'])) { if ($_FILES['avatar']['size'] > $max_image_size) { $image_too_big = 1; } } if ($image_too_big == 1) { echo "<font color='#CC0000'>"; echo "The uploaded image is too big"; echo "</font>"; echo "<br>"; echo "<br>"; } else { $af_size = GetImageSize($_FILES[$image]['tmp_name']); switch ($af_size[2]) { case 1: $thispicext = 'gif'; break; case 2: $thispicext = 'jpg'; break; case 3: $thispicext = 'png'; break; } // if ( $af_size[2] >= 1 && $af_size[2] <= 3) { // 1=GIF, 2=JPG or 3=PNG if ($af_size[2] >= 2 && $af_size[2] <= 3) { // 2=JPG or 3=PNG $pict_jpg = $absolute_path . "/images/discussions/users/" . $user_id . "_t.jpg"; if (file_exists($pict_jpg)) { unlink($pict_jpg); } $pic_jpg = $absolute_path . "/images/discussions/users/" . $user_id . ".jpg"; if (file_exists($pic_jpg)) { unlink($pic_jpg); } $pict_png = $absolute_path . "/images/discussions/users/" . $user_id . "_t.png"; if (file_exists($pict_png)) { unlink($pict_png); } $pic_png = $absolute_path . "/images/discussions/users/" . $user_id . ".png"; if (file_exists($pic_png)) { unlink($pic_png); } $pict_gif = $absolute_path . "/images/discussions/users/" . $user_id . "_t.gif"; if (file_exists($pict_gif)) { unlink($pict_gif); } $pic_gif = $absolute_path . "/images/discussions/users/" . $user_id . ".gif"; if (file_exists($pic_gif)) { unlink($pic_gif); } chmod($_FILES[$image]['tmp_name'], 0644); // 1. if directory ./avatars/USERID does not exist, create it // 2. create the subdirs for ORIGINAL, LARGE (128) and SMALL(32) if (!is_dir($af_dir_ads . $user_id)) { mkdir($af_dir_ads . $user_id); mkdir($af_dir_ads . $user_id . "/original"); // ORIGINAL mkdir($af_dir_ads . $user_id . "/large"); // LARGE (128) mkdir($af_dir_ads . $user_id . "/small"); // SMALL (32) } $original_image = $af_dir_ads . $user_id . "/original/" . $user_id . "." . $thispicext; $large_image = $af_dir_ads . $user_id . "/large/" . $user_id . "." . $thispicext; $small_image = $af_dir_ads . $user_id . "/small/" . $user_id . "." . $thispicext; // copy original image to folder "original" move_uploaded_file($_FILES[$image]['tmp_name'], $original_image); // create "large" image 128px switch ($af_size[2]) { case 1: $src = ImageCreateFromGif($original_image); break; case 2: $src = ImageCreateFromJpeg($original_image); break; case 3: $src = ImageCreateFromPng($original_image); break; } $width_before = ImageSx($src); $height_before = ImageSy($src); if ($width_before >= $height_before) { $width_new = min(128, $width_before); $scale = $width_before / $height_before; $height_new = round($width_new / $scale); } else { $height_new = min(128, $height_before); $scale = $height_before / $width_before; $width_new = round($height_new / $scale); } $dst = ImageCreateTrueColor($width_new, $height_new); // GD Lib 2 ImageCopyResampled($dst, $src, 0, 0, 0, 0, $width_new, $height_new, $width_before, $height_before); switch ($af_size[2]) { case 1: ImageGIF($dst, $large_image); break; case 2: ImageJPEG($dst, $large_image); break; case 3: ImagePNG($dst, $large_image); break; } imagedestroy($dst); imagedestroy($src); // create "small" image 32px switch ($af_size[2]) { case 1: $src = ImageCreateFromGif($original_image); break; case 2: $src = ImageCreateFromJpeg($original_image); break; case 3: $src = ImageCreateFromPng($original_image); break; } $width_before = ImageSx($src); $height_before = ImageSy($src); if ($width_before >= $height_before) { $width_new = min(32, $width_before); $scale = $width_before / $height_before; $height_new = round($width_new / $scale); } else { $height_new = min(32, $height_before); $scale = $height_before / $width_before; $width_new = round($height_new / $scale); } $dst = ImageCreateTrueColor($width_new, $height_new); // GD Lib 2 ImageCopyResampled($dst, $src, 0, 0, 0, 0, $width_new, $height_new, $width_before, $height_before); switch ($af_size[2]) { case 1: ImageGIF($dst, $small_image); break; case 2: ImageJPEG($dst, $small_image); break; case 3: ImagePNG($dst, $small_image); break; } imagedestroy($dst); imagedestroy($src); // DB update $sql = "UPDATE #__discussions_users SET avatar='" . $user_id . "." . $thispicext . "' WHERE id=" . $user_id; $db->setQuery($sql); if ($db->getErrorNum()) { echo $db->stderr(); } else { $db->query(); } } } }
/** * Create thumbnail from specified original image file. * * @param object $s3 S3 instance * @param string $key * @param string $filename */ private function create_thumbnail($s3, $key, $filename) { // Create Same Size Thumbnail $f = TMP . $filename; $src_image = imagecreatefromjpeg($f); // get size $width = ImageSx($src_image); $height = ImageSy($src_image); // Tatenaga... if ($height > $width * 0.75) { $src_y = (int) ($height - $width * 0.75); $src_h = $height - $src_y; $src_x = 0; $src_w = $width; } else { // Yokonaga $src_y = 0; $src_h = $height; $src_x = 0; $src_w = $height / 0.75; } // get resized size $dst_w = 320; $dst_h = 240; // generate file $dst_image = ImageCreateTrueColor($dst_w, $dst_h); ImageCopyResampled($dst_image, $src_image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); imagejpeg($dst_image, TMP . $key . '/thumbnail.jpg'); // store thumbnail to S3 $s3->putObject(array('Bucket' => Configure::read('image_bucket_name'), 'Key' => $key . '/thumbnail.jpg', 'SourceFile' => TMP . $key . '/thumbnail.jpg', 'ContentType' => 'image/jpeg', 'ACL' => 'public-read', 'StorageClass' => 'REDUCED_REDUNDANCY')); }
function finishUpload($image_file, $type, $size, $name) { global $dbi; $filesize = filesize($image_file); if (!($fp = @fopen($image_file, 'rb'))) { trigger_error("Can't open file {$image_file}", E_USER_WARNING); die; } $data = fread($fp, $filesize); switch ($type) { case "image/jpeg": // generate thumbnail $src_img = ImageCreateFromJPEG($image_file); // create a image resource with your original image in it if (!$src_img) { trigger_error("Can't create image from jpeg", E_USER_WARNING); die; } $width = ImageSx($src_img); //get original image width $height = ImageSy($src_img); //get original image height //scale the image $dest_width = 50; $dest_height = 50; $dest_img = ImageCreate($dest_width, $dest_height); if (!$dest_img) { trigger_error("Can't create thubnails canvas", E_USER_WARNING); die; } $result = ImageCopyResized($dest_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); if (!$result) { trigger_error("Can't resize the image", E_USER_WARNING); die; } ob_start(); ImageJPEG($dest_img); $thumbnail = ob_get_contents(); ob_end_clean(); break; case "image/gif": // generate thumbnail $src_img = ImageCreateFromGIF($image_file); // create a image resource with your original image in it if (!$src_img) { trigger_error("Can't create image from gif", E_USER_WARNING); die; } $width = ImageSx($src_img); //get original image width $height = ImageSy($src_img); //get original image height //scale the image $dest_width = 50; $dest_height = 50; $dest_img = ImageCreate($dest_width, $dest_height); if (!$dest_img) { trigger_error("Can't create thubnails canvas", E_USER_WARNING); die; } $result = ImageCopyResized($dest_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); if (!$result) { trigger_error("Can't resize the image", E_USER_WARNING); die; } ob_start(); ImageGIF($dest_img); $thumbnail = ob_get_contents(); ob_end_clean(); break; default: Header("Location: " . $_SERVER['PHP_SELF'] . "?error=1"); die; break; } // populate db $now = date("Y/m/d"); $data = addslashes($data); $thumbnail = addslashes($thumbnail); $res = sql_query("INSERT INTO jones_binarydata VALUES( NULL, '{$name}', '{$size}', '{$type}', '{$now}', '', '{$data}', '{$width}', '{$height}', '{$thumbnail}', '0' )", $dbi); ImageDestroy($dest_img); ImageDestroy($src_img); if ($res) { Header("Location: " . $_SERVER['PHP_SELF']); } }
function upMultImageWithThumb($destpath, $thumbPath, $file, $n_width, $n_height) { $path = ''; while (list($key, $value) = each($_FILES[$file]["name"])) { if (!empty($value)) { if ($_FILES[$file]["type"][$key] == "image/gif" || $_FILES[$file]["type"][$key] == "image/jpeg" || $_FILES[$file]["type"][$key] == "image/pjpeg" || $_FILES[$file]["type"][$key] == "image/png" && $_FILES[$file]["size"][$key] < 2000000) { $source = $_FILES[$file]["tmp_name"][$key]; $filename = $_FILES[$file]["name"][$key]; move_uploaded_file($source, $destpath . $filename); //echo "Uploaded: " . $destpath . $filename . "<br/>" ; $path .= $filename . '***'; //thumbnail creation start// $tsrc = $thumbPath . $_FILES[$file]["name"][$key]; // Path where thumb nail image will be stored //$n_width = 100; // Fix the width of the thumb nail images //$n_height = 100; // Fix the height of the thumb nail imaage /////////////////////////////////////////////// Starting of GIF thumb nail creation/////////// $add = $destpath . $filename; if ($_FILES[$file]["type"][$key] == "image/gif") { //echo "hello"; $im = ImageCreateFromGIF($add); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); if (function_exists("imagegif")) { Header("Content-type: image/gif"); ImageGIF($newimage, $tsrc); } if (function_exists("imagejpeg")) { Header("Content-type: image/jpeg"); ImageJPEG($newimage, $tsrc); } } //chmod("$tsrc",0777); ////////// end of gif file thumb nail creation////////// //$n_width=100; // Fix the width of the thumb nail images //$n_height=100; // Fix the height of the thumb nail imaage ////////////// starting of JPG thumb nail creation////////// if ($_FILES[$file]["type"][$key] == "image/jpeg") { //echo $_FILES[$file]["name"][$key]."<br>"; $im = ImageCreateFromJPEG($add); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); ImageJpeg($newimage, $tsrc); chmod("{$tsrc}", 0777); } //////////////// End of png thumb nail creation ////////// if ($_FILES[$file]["type"][$key] == "image/png") { //echo "hello"; $im = ImageCreateFromPNG($add); $width = ImageSx($im); // Original picture width is stored $height = ImageSy($im); // Original picture height is stored $newimage = imagecreatetruecolor($n_width, $n_height); imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); if (function_exists("imagepng")) { //Header("Content-type: image/png"); ImagePNG($newimage, $tsrc); } if (function_exists("imagejpeg")) { //Header("Content-type: image/jpeg"); ImageJPEG($newimage, $tsrc); } } // thumbnail creation end--- } else { $msg = "error in upload"; //return $msg; } } //if } //while $cnt = strlen($path) - 3; $pathnw = substr_replace($path, '', $cnt, 3); return $pathnw; }
function thumbnailImage($imageBitsIn, $contentType) { // Create a GD image $imageIn = ImageCreateFromString($imageBitsIn); // Measure the image $inX = ImageSx($imageIn); $inY = ImageSy($imageIn); // Decide how to scale it if ($inX > $inY) { $outX = THUMB_SIZE; $outY = (int) (THUMB_SIZE * ((double) $inY / $inX)); } else { $outX = (int) (THUMB_SIZE * ((double) $inX / $inY)); $outY = THUMB_SIZE; } // Create thumbnail image and fill it with white $imageOut = ImageCreateTrueColor($outX, $outY); ImageFill($imageOut, 0, 0, ImageColorAllocate($imageOut, 255, 255, 255)); // Copy / resize the original image into the thumbnail image ImageCopyResized($imageOut, $imageIn, 0, 0, 0, 0, $outX, $outY, $inX, $inY); // Write the image to a temporary file in the requested format $fileOut = tempnam("/tmp", "aws") . ".aws"; switch ($contentType) { case "image/jpg": $ret = ImageJPEG($imageOut, $fileOut, 100); break; case "image/png": $ret = ImagePNG($imageOut, $fileOut, 0); break; case "image/gif": $ret = ImageGIF($imageOut, $fileOut); break; default: unlink($fileOut); return false; } // Verify success if (!$ret) { unlink($fileOut); return false; } // Read the image back in $imageBitsOut = file_get_contents($fileOut); // Clean up unlink($fileOut); return $imageBitsOut; }
function Image_Get_Size($Source) { /****************************************************************************/ $__args_types = array('string'); #----------------------------------------------------------------------------- $__args__ = Func_Get_Args(); eval(FUNCTION_INIT); /****************************************************************************/ if (!Function_Exists('ImageCreateFromString')) { return ERROR | Trigger_Error('[Image_Get_Size]: модуль работы с изображениями не установлен'); } #----------------------------------------------------------------------------- $Real = @ImageCreateFromString($Source); if (!Is_Resource($Real)) { return ERROR | @Trigger_Error("[Image_Get_Size]: не возможно создать изображение"); } #----------------------------------------------------------------------------- $Sx = @ImageSx($Real); if (!$Sx) { return ERROR | @Trigger_Error("[Image_Get_Size]: не возможно получить ширину изображения"); } #----------------------------------------------------------------------------- $Sy = @ImageSy($Real); if (!$Sy) { return ERROR | @Trigger_Error("[Image_Get_Size]: не возможно получить высоту изображения"); } #----------------------------------------------------------------------------- return array('Width' => $Sx, 'Height' => $Sy); }