function generate_thumbnail($file, $mime) { global $config; gd_capabilities(); list($file_type, $exact_type) = explode("/", $mime); if (_JB_GD_INSTALLED && ($file_type = "image")) { if ($exact_type != "gif" && $exact_type != "png" && $exact_type != "jpeg") { return false; } if ($exact_type == "gif" && !_JB_GD_GIF) { return false; } if ($exact_type == "png" && !_JB_GD_PNG) { return false; } if ($exact_type == "jpeg" && !_JB_GD_JPG) { return false; } // Load up the original and get size // NOTE: use imageCreateFromString to avoid to have to check what type of image it is $original = imageCreateFromString(file_get_contents($file)); $original_w = imagesX($original); $original_h = imagesY($original); // Only if the image is really too big, resize it // NOTE: if image is smaller than target size, don't do anything. // We *could* copy the original to filename_thumb, but since it's the same // it would be a waste of precious resources if ($original_w > $config['uploader']['thumb_w'] || $original_h > $config['uploader']['thumb_h']) { // If original is wider than it's high, resize the width and vice versa // NOTE: '>=' cause otherwise it's possible that $scale isn't computed if ($original_w >= $original_h) { $scaled_w = $config['uploader']['thumb_w']; // Figure out how much smaller that target is than original // and apply it to height $scale = $config['uploader']['thumb_w'] / $original_w; $scaled_h = ceil($original_h * $scale); } elseif ($original_w <= $original_h) { $scaled_h = $config['uploader']['thumb_h']; $scale = $config['uploader']['thumb_h'] / $original_h; $scaled_w = ceil($original_w * $scale); } } else { // Break out of if($file_type = image) since no resize is possible return false; } // Scale the image $scaled = imageCreateTrueColor($scaled_w, $scaled_h); imageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h); // Store thumbs in jpeg, hope no one minds the 100% quality lol imageJpeg($scaled, $file . "_thumb", 100); // Let's be nice to our server imagedestroy($scaled); imagedestroy($original); return true; } }
public function __construct($handle) { $mimeType = Type::guessType($handle); if (!isset($this->_formatMap[$mimeType])) { throw new OutOfBoundsException("Could not map MIME-type `{$mimeType}` to format."); } $this->_format = $this->_formatMap[$mimeType]; $this->_object = imageCreateFromString(stream_get_contents($handle)); if (!$this->_isResource($this->_object)) { throw new Exception("Was not able to create image from handle."); } if (imageIsTrueColor($this->_object)) { imageAlphaBlending($this->_object, false); imageSaveAlpha($this->_object, true); } }
function Cartoonfy($p_image, $p_triplevel, $p_diffspace) { $this->triplevel = (int) (2000.0 + 5000.0 * $p_triplevel); $this->diffspace = (int) ($p_diffspace * 32.0); $this->i0 = imageCreateFromString(file_get_contents($p_image)); if ($this->i0) { $this->i1 = imageCreateTrueColor(imageSx($this->i0), imageSy($this->i0)); for ($x = (int) $this->diffspace; $x < imageSx($this->i0) - (1 + (int) $this->diffspace); $x++) { for ($y = (int) $this->diffspace; $y < imageSy($this->i0) - (1 + (int) $this->diffspace); $y++) { $t = Cartoonfy::GetMaxContrast($x, $y); if ($t > $this->triplevel) { imageSetPixel($this->i1, $x, $y, 0); } else { imageSetPixel($this->i1, $x, $y, Cartoonfy::FlattenColor(imageColorAt($this->i0, $x, $y))); } } //usleep(1000); } imageDestroy($this->i0); } else { print "<b>" . $p_image . "</b> is not supported image format!"; exit; } }
/** * Resamples (convert/resize) an image file. You can specify a new width, height and type * @param string $file Image path and file name * @param int $w Width * @param int $h Height * @param string $type Supported image types: gif,png,jpg,bmp,xbmp,wbmp. Defaults to jpg * @return boolean */ public static function imageResample($file, $w, $h, $type = null) { if (!function_exists('imagecreatefromstring')) { Raxan::log('Function imagecreatefromstring does not exists - The GD image processing library is required.', 'warn', 'Raxan::imageResample'); return false; } $info = @getImageSize($file); if ($info) { // maintain aspect ratio if ($h == 0) { $h = $info[1] * ($w / $info[0]); } if ($w == 0) { $w = $info[0] * ($h / $info[1]); } if ($w == 0 && $h == 0) { $w = $info[0]; $h = $info[1]; } // resize/resample image $img = @imageCreateFromString(file_get_contents($file)); if (!$img) { return false; } $newImg = function_exists('imagecreatetruecolor') ? imageCreateTrueColor($w, $h) : imageCreate($w, $h); if (function_exists('imagecopyresampled')) { imageCopyResampled($newImg, $img, 0, 0, 0, 0, $w, $h, $info[0], $info[1]); } else { imageCopyResized($newImg, $img, 0, 0, 0, 0, $w, $h, $info[0], $info[1]); } imagedestroy($img); $type = !$type ? $info[2] : strtolower(trim($type)); if ($type == 1 || $type == 'gif') { $f = 'imagegif'; } else { if ($type == 3 || $type == 'png') { $f = 'imagepng'; } else { if ($type == 6 || $type == 16 || $type == 'bmp' || $type == 'xbmp') { $f = 'imagexbm'; } else { if ($type == 15 || $type == 'wbmp') { $f = 'image2wbmp'; } else { $f = 'imagejpeg'; } } } } if (function_exists($f)) { $f($newImg, $file); } imagedestroy($newImg); return true; } return false; }
/** * Appends information about the source image to the thumbnail. * * @param string $thumbnail * @return string */ protected function appendSourceInfo($thumbnail) { if (!function_exists('imageCreateFromString') || !function_exists('imageCreateTrueColor')) { return $thumbnail; } $imageSrc = imageCreateFromString($thumbnail); // get image size $width = imageSX($imageSrc); $height = imageSY($imageSrc); // increase height $heightDst = $height + self::$sourceInfoLineHeight * 2; // create new image $imageDst = imageCreateTrueColor($width, $heightDst); imageAlphaBlending($imageDst, false); // set background color $background = imageColorAllocate($imageDst, 102, 102, 102); imageFill($imageDst, 0, 0, $background); // copy image imageCopy($imageDst, $imageSrc, 0, 0, 0, 0, $width, $height); imageSaveAlpha($imageDst, true); // get font size $font = 2; $fontWidth = imageFontWidth($font); $fontHeight = imageFontHeight($font); $fontColor = imageColorAllocate($imageDst, 255, 255, 255); // write source info $line1 = $this->sourceName; // imageString supports only ISO-8859-1 encoded strings if (CHARSET != 'ISO-8859-1') { $line1 = StringUtil::convertEncoding(CHARSET, 'ISO-8859-1', $line1); } // truncate text if necessary $maxChars = floor($width / $fontWidth); if (strlen($line1) > $maxChars) { $line1 = $this->truncateSourceName($line1, $maxChars); } $line2 = $this->sourceWidth . 'x' . $this->sourceHeight . ' ' . FileUtil::formatFilesize($this->sourceSize); // write line 1 // calculate text position $textX = 0; $textY = 0; if ($fontHeight < self::$sourceInfoLineHeight) { $textY = intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2)); } if (strlen($line1) * $fontWidth < $width) { $textX = intval(round(($width - strlen($line1) * $fontWidth) / 2)); } imageString($imageDst, $font, $textX, $height + $textY, $line1, $fontColor); // write line 2 // calculate text position $textX = 0; $textY = 0; if ($fontHeight < self::$sourceInfoLineHeight) { $textY = self::$sourceInfoLineHeight + intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2)); } if (strlen($line2) * $fontWidth < $width) { $textX = intval(round(($width - strlen($line2) * $fontWidth) / 2)); } imageString($imageDst, $font, $textX, $height + $textY, $line2, $fontColor); // output image ob_start(); if ($this->imageType == 1 && function_exists('imageGIF')) { @imageGIF($imageDst); $this->mimeType = 'image/gif'; } else { if (($this->imageType == 1 || $this->imageType == 3) && function_exists('imagePNG')) { @imagePNG($imageDst); $this->mimeType = 'image/png'; } else { if (function_exists('imageJPEG')) { @imageJPEG($imageDst, null, 90); $this->mimeType = 'image/jpeg'; } else { return false; } } } @imageDestroy($imageDst); $thumbnail = ob_get_contents(); ob_end_clean(); return $thumbnail; }
/** * Load the image and resize it using the assigned strategy. * @param string $filename Filename of the input file. * @return resource GD image resource. */ protected function _resize($filename) { $image = imageCreateFromString(file_get_contents($filename)); if (false === $image) { throw new Zend_Filter_Exception('Can\'t load image: ' . $filename); } $resized = $this->getStrategy()->resize($image, $this->getWidth(), $this->getHeight()); return $resized; }
'pro_title' : pro_title, 'Edi':edit }, success: function(response){ window.location.href = 'campaign_dash.php'; return false; <?php //$promotion_no="23"; $Img = 'upload/file_' . $promotion_no . '.png'; if ($_POST['file'] != "") { //@header('Content-Type: application/json'); $file = base64_decode(str_replace('data:image/png;base64,', '', $_POST['file'])); $im = imageCreateFromString($file); if ($im) { $save = imagepng($im, 'upload/file_' . $promotion_no . '.png'); // if(isset($_post['saveme'])){ $qry = "INSERT INTO promotion VALUES ('','{$parentemail}','{$save_div}','{$Img}','','{$promotion_no}','{$pro_title}','{$pro_id}')"; $res = mysqli_query($conn, $qry); //} // echo $pro_title=$_POST['pro_title']; echo json_encode(array('file' => true)); } else { echo json_encode(array('error' => 'Could not parse image string.')); } //exit(); } ?>
function add_watermark($image_path, $watermark_path, $type = 'show') { $this->image_data = $type == 'return' ? array('mime' => $this->getFileType($image_path, 'mime')) : getImageSize($image_path); $this->image = $type == 'return' ? imageCreateFromString($image_path) : $this->ImageCreateFromType($image_path, $this->image_data['mime']); ImageAlphaBlending($this->image, true); $this->watermark_data = getimagesize($watermark_path); $this->watermark = $this->ImageCreateFromType($watermark_path, $this->watermark_data['mime']); $image_width = ImageSX($this->image); $image_height = ImageSY($this->image); $watermark_width = ImageSX($this->watermark); $watermark_height = ImageSY($this->watermark); $full_offset_x = $image_width - $watermark_width; $full_offset_y = $image_height - $watermark_height; $half_offset_x = ($image_width - $watermark_width) / 2; $half_offset_y = ($image_height - $watermark_height) / 2; if ($this->watermark_random_position == 'yes') { $random_full_offset_x = $full_offset_x - 40; $random_full_offset_y = $full_offset_y - 40; $x = rand(20, $random_full_offset_x); $y = rand(20, $random_full_offset_y); } else { $offset = $this->offset; switch ($this->align_to) { case 'lt': $x = $offset['x']; $y = $offset['y']; break; case 'ct': $x = $half_offset_x + $offset['x']; $y = $offset['y']; break; case 'rt': $x = $offset['x'] + $full_offset_x; $y = $offset['y']; break; case 'lc': $x = $offset['x']; $y = $offset['y'] + $half_offset_y; break; case 'cc': $x = $offset['x'] + $half_offset_x; $y = $offset['y'] + $half_offset_y; break; case 'rc': $x = $offset['x'] + $full_offset_x; $y = $offset['y'] + $half_offset_y; break; case 'lb': $x = $offset['x']; $y = $offset['y'] + $full_offset_y; break; case 'cb': $x = $offset['x'] + $half_offset_x; $y = $offset['y'] + $full_offset_y; break; case 'rb': $x = $offset['x'] + $full_offset_x; $y = $offset['y'] + $full_offset_y; break; } } $temp = imagecreatetruecolor($watermark_width, $watermark_height); imagecopy($temp, $this->image, 0, 0, $x, $y, $watermark_width, $watermark_height); imagecopy($temp, $this->watermark, 0, 0, 0, 0, $watermark_width, $watermark_height); imagecopymerge($this->image, $temp, $x, $y, 0, 0, $watermark_width, $watermark_height, $this->watermark_opacity); $this->is_added_watermark = true; switch ($type) { case 'show': $this->show_image(); break; case 'save': $this->show_image('string'); break; case 'return': return $this->return_image(); break; } }
/** * Validate image. * * @param string $image string representing image, for example, result of base64_decode() * * @throws APIException if image size is 1MB or greater. * @throws APIException if file format is unsupported, GD can not create image from given string */ protected function checkImage($image) { // check size if (strlen($image) > ZBX_MAX_IMAGE_SIZE) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Image size must be less than 1MB.')); } // check file format if (@imageCreateFromString($image) === false) { self::exception(ZBX_API_ERROR_PARAMETERS, _('File format is unsupported.')); } }
/** * Initialize a layer from a string (obtains with file_get_contents, cURL...) * * This not recommanded to initialize JPEG string with this method, GD displays bugs ! * * @param string $imageString * * @return ImageWorkshopLayer */ public static function initFromString($imageString) { return new ImageWorkshopLayer(imageCreateFromString($imageString)); }
function shareImage() { global $cfg, $db; if ($cfg['image_share_mode'] == 'played') { $query = mysql_query('SELECT image, artist, album, filesize, filemtime, album.album_id FROM counter, album, bitmap WHERE counter.flag <= 1 AND counter.album_id = album.album_id AND counter.album_id = bitmap.album_id ORDER BY counter.time DESC LIMIT 1'); $bitmap = mysql_fetch_assoc($query); $text = 'Recently played:'; } else { $query = mysql_query('SELECT image, artist, album, filesize, filemtime, album.album_id FROM album, bitmap WHERE album.album_id = bitmap.album_id ORDER BY album_add_time DESC LIMIT 1'); $bitmap = mysql_fetch_assoc($query); $text = 'New album:'; $cfg['image_share_mode'] = 'new'; } $etag = '"' . md5($bitmap['album_id'] . $cfg['image_share_mode'] . $bitmap['filemtime'] . '-' . $bitmap['filesize'] . '-' . filemtime('image/share.png')) . '"'; if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) { header('HTTP/1.1 304 Not Modified'); header('ETag: ' . $etag); header('Cache-Control: max-age=5'); exit; } // Background (253 x 52 pixel) $dst_image = imageCreateFromPng('image/share.png'); // Image copy source NJB_IMAGE_SIZE x NJB_IMAGE_SIZE => 50x50 $src_image = imageCreateFromString($bitmap['image']); imageCopyResampled($dst_image, $src_image, 1, 1, 0, 0, 50, 50, NJB_IMAGE_SIZE, NJB_IMAGE_SIZE); imageDestroy($src_image); // Text $font = NJB_HOME_DIR . 'fonts/DejaVuSans.ttf'; $font_color = imagecolorallocate($dst_image, 0, 0, 99); imagettftext($dst_image, 8, 0, 55, 13, $font_color, $font, $text); imagettftext($dst_image, 8, 0, 55, 30, $font_color, $font, $bitmap['artist']); imagettftext($dst_image, 8, 0, 55, 47, $font_color, $font, $bitmap['album']); // For to long text overwrite 4 pixels right margin $src_image = imageCreateFromPng('image/share.png'); ImageCopy($dst_image, $src_image, 249, 0, 249, 0, 4, 52); imageDestroy($src_image); // Buffer data ob_start(); ImagePng($dst_image); $data = ob_get_contents(); ob_end_clean(); imageDestroy($dst_image); header('Cache-Control: max-age=5'); streamData($data, 'image/jpeg', false, false, $etag); }
function waterMark($original, $watermark = 'watermark.png', $placement = 'bottom=10,right=10', $destination = null) { $info_o = @getImageSize($original); if (!$info_o) { return false; } $info_w = @getImageSize($watermark); if (!$info_w) { return false; } list($vertical, $horizontal) = explode(',', $placement); list($vertical, $sy) = explode('=', trim($vertical)); list($horizontal, $sx) = explode('=', trim($horizontal)); switch (trim($vertical)) { case 'bottom': $y = $info_o[1] - $info_w[1] - (int) $sy; break; case 'middle': $y = ceil($info_o[1] / 2) - ceil($info_w[1] / 2) + (int) $sy; break; default: $y = (int) $sy; break; } switch (trim($horizontal)) { case 'right': $x = $info_o[0] - $info_w[0] - (int) $sx; break; case 'center': $x = ceil($info_o[0] / 2) - ceil($info_w[0] / 2) + (int) $sx; break; default: $x = (int) $sx; break; } //header("Content-Type: ".$info_o['mime']); $f = $this->createFuncName; $isrc = $f($this->file); $idest = imagecreatetruecolor($info_o[0], $info_o[1]); $iWatermark = @imageCreateFromString(file_get_contents($watermark)); $iOriginal = @imageCreateFromString(file_get_contents($original)); imageAlphaBlending($idest, true); imageSaveAlpha($idest, true); imageCopy($idest, $iOriginal, 0, 0, 0, 0, $info_o[0], $info_o[1]); imageCopy($idest, $iWatermark, $x, $y, 0, 0, $info_w[0], $info_w[1]); if ($this->format == 'jpeg') { $f = $this->outputFuncName; $f($idest, $original, $this->outputQuality); } else { $f = $this->outputFuncName; $f($idest, $original); } imagedestroy($iOriginal); imagedestroy($idest); imageDestroy($iWatermark); return true; }
function waterMark($original, $watermark, $placement = 'bottom=0,right=0', $destination) { $info_o = @getImageSize($original); if (!$info_o) { return false; } $info_w = @getImageSize($watermark); if (!$info_w) { return false; } list($vertical, $horizontal) = explode(',', $placement, 2); list($vertical, $sy) = explode('=', trim($vertical), 2); list($horizontal, $sx) = explode('=', trim($horizontal), 2); switch (trim($vertical)) { case 'bottom': $y = $info_o[1] - $info_w[1] - (int) $sy; break; case 'middle': $y = ceil($info_o[1] / 2) - ceil($info_w[1] / 2) + (int) $sy; break; default: $y = (int) $sy; break; } switch (trim($horizontal)) { case 'right': $x = $info_o[0] - $info_w[0] - (int) $sx; break; case 'center': $x = ceil($info_o[0] / 2) - ceil($info_w[0] / 2) + (int) $sx; break; default: $x = (int) $sx; break; } $original = @imageCreateFromString(file_get_contents($original)); $watermark = @imageCreateFromString(file_get_contents($watermark)); $out = imageCreateTrueColor($info_o[0], $info_o[1]); imageCopy($out, $original, 0, 0, 0, 0, $info_o[0], $info_o[1]); if ($info_o[0] > 60 && $info_o[1] > 60) { imageCopy($out, $watermark, $x, $y, 0, 0, $info_w[0], $info_w[1]); } switch ($info_o[2]) { case 1: imageGIF($out, $destination); break; case 2: imageJPEG($out, $destination); break; case 3: imagePNG($out, $destination); break; } imageDestroy($out); imageDestroy($original); imageDestroy($watermark); return true; }
function read_image_descriptor() { /* Reset global variables */ $this->buffer = array(); $this->fou = ''; /* Header -> GIF89a */ $this->fou .= "GIF89a"; $this->getbytes(9); for ($i = 0; $i < 9; $i++) { $this->image_descriptor[$i] = $this->buffer[$i]; } $local_color_table_flag = $this->buffer[8] & 0x80 ? TRUE : FALSE; if ($local_color_table_flag) { $code = $this->buffer[8] & 0x7; $sorted = $this->buffer[8] & 0x20 ? TRUE : FALSE; } else { $code = $this->global_color_table_code; $sorted = $this->global_sorted; } $size = 2 << $code; $this->logical_screen_descriptor[4] &= 0x70; $this->logical_screen_descriptor[4] |= 0x80; $this->logical_screen_descriptor[4] |= $code; if ($sorted) { $this->logical_screen_descriptor[4] |= 0x8; } $this->putbytes($this->logical_screen_descriptor, 7); if ($local_color_table_flag) { $this->getbytes(3 * $size); $this->putbytes($this->buffer, 3 * $size); } else { $this->putbytes($this->global, 3 * $size); } $this->fou .= ","; $this->image_descriptor[8] &= 0x40; $this->putbytes($this->image_descriptor, 9); /* LZW minimum code size */ $this->getbytes(1); $this->putbytes($this->buffer, 1); /* Image Data */ for (;;) { $this->getbytes(1); $this->putbytes($this->buffer, 1); if (($u = $this->buffer[0]) == 0) { break; } $this->getbytes($u); $this->putbytes($this->buffer, $u); } /* trailer */ $this->fou .= ";"; /* Write to file */ switch ($this->fm) { /* Write as BMP */ case "BMP": $im = imageCreateFromString($this->fou); $framename = $this->sp . $this->image_count++ . ".bmp"; if (!$this->imageBmp($im, $framename)) { $this->es = "error #3"; return 0; } imageDestroy($im); break; /* Write as PNG */ /* Write as PNG */ case "PNG": $im = imageCreateFromString($this->fou); $framename = $this->sp . $this->image_count++ . ".png"; if (!imagePng($im, $framename)) { $this->es = "error #3"; return 0; } imageDestroy($im); break; /* Write as JPG */ /* Write as JPG */ case "JPG": $im = imageCreateFromString($this->fou); $framename = $this->sp . $this->image_count++ . ".jpg"; if (!imageJpeg($im, $framename)) { $this->es = "error #3"; return 0; } imageDestroy($im); break; /* Write as GIF */ /* Write as GIF */ case "GIF": $im = imageCreateFromString($this->fou); $framename = $this->output . $this->sp . ".gif"; if (!imageGif($im, $framename)) { $this->es = "error #3"; return 0; } imageDestroy($im); break; } }
/** * Initialize a layer from a string (obtains with file_get_contents, cURL...) * * This not recommanded to initialize JPEG string with this method, GD displays bugs ! * * @param string $imageString * * @return ImageWorkshopLayer */ public static function initFromString($imageString) { if (!($image = @imageCreateFromString($imageString))) { throw new ImageWorkshopException('Can\'t generate an image from the given string.', static::ERROR_CREATE_IMAGE_FROM_STRING); } return new ImageWorkshopLayer($image); }
} switch ($_GET['action']) { case 'image': $W = (int) $_GET["w"]; if ($W < 10) { $W = 100; } $im = imageCreateTrueColor($W, $W); imagesavealpha($im, false); $black = imageColorAllocate($im, 0, 0, 0); $transparent = imagecolortransparent($im, $black); imagefilledRectangle($im, 0, 0, imageSx($im), imageSy($im), $transparent); $img = $own->findImage($_GET['img']); $ext = strtolower(substr(projectPath . '/data/' . $img['i_file'], strrpos(projectPath . '/data/' . $img['i_file'], "."))); if ($ext == ".jpg" || $ext == ".png") { $orig = imageCreateFromString(file_get_contents(projectPath . '/data/' . $img['i_file'])); /*} else if($ext==".png") { $orig = imageCreateFromPng(projectPath.'/data/'.$img['i_file']); */ } else { die("Wrong extension."); } $wh = imageSx($orig); if (imageSy($orig) < $wh) { $wh = imageSy($orig); } if ($img['i_set'] > 0 && isset($_GET['set'])) { imagecopyresampled($im, $orig, 0 + $W / 8, 0 + $W / 8, imageSx($orig) / 2 - $wh / 2, imageSy($orig) / 2 - $wh / 2, $W - $W / 4, $W - $W / 4, $wh, $wh); } else { imagecopyresampled($im, $orig, 0, 0, imageSx($orig) / 2 - $wh / 2, imageSy($orig) / 2 - $wh / 2, $W, $W, $wh, $wh); }
/** * Open the source and target image for processing it * * @param Asido_TMP &$tmp * @return boolean * @access protected */ function __open(&$tmp) { $error_source = false; $error_target = false; // get image dimensions // if ($i = @getImageSize($tmp->source_filename)) { $tmp->image_width = $i[0]; $tmp->image_height = $i[1]; } // image type ? // switch (@$i[2]) { case 1: // GIF $error_source = false == ($tmp->source = @imageCreateFromGIF($tmp->source_filename)); $error_target = false == ($tmp->target = imageCreateTrueColor($tmp->image_width, $tmp->image_height)); $error_target &= imageCopyResampled($tmp->target, $tmp->source, 0, 0, 0, 0, $tmp->image_width, $tmp->image_height, $tmp->image_width, $tmp->image_height); break; case 2: // JPG $error_source = false == ($tmp->source = imageCreateFromJPEG($tmp->source_filename)); $error_target = false == ($tmp->target = imageCreateFromJPEG($tmp->source_filename)); break; case 3: // PNG $error_source = false == ($tmp->source = @imageCreateFromPNG($tmp->source_filename)); $error_target = false == ($tmp->target = @imageCreateFromPNG($tmp->source_filename)); break; case 15: // WBMP $error_source = false == ($tmp->source = @imageCreateFromWBMP($tmp->source_filename)); $error_target = false == ($tmp->target = @imageCreateFromWBMP($tmp->source_filename)); break; case 16: // XBM $error_source = false == ($tmp->source = @imageCreateFromXBM($tmp->source_filename)); $error_target = false == ($tmp->target = @imageCreateFromXBM($tmp->source_filename)); break; case 4: // SWF // SWF case 5: // PSD // PSD case 6: // BMP // BMP case 7: // TIFF(intel byte order) // TIFF(intel byte order) case 8: // TIFF(motorola byte order) // TIFF(motorola byte order) case 9: // JPC // JPC case 10: // JP2 // JP2 case 11: // JPX // JPX case 12: // JB2 // JB2 case 13: // SWC // SWC case 14: // IFF // IFF default: $error_source = false == ($tmp->source = @imageCreateFromString(file_get_contents($tmp->source_filename))); $error_target = false == ($tmp->source = @imageCreateFromString(file_get_contents($tmp->source_filename))); break; } return !($error_source || $error_target); }
public function getScaled($fn, $w, $h, $rot = 0, $square = 1, $watermark = true) { if (rand(0, 100) > 80) { $this->unlinkOld(); } $ext = strtolower(substr(projectPath . '/data/' . $fn, strrpos(projectPath . '/data/' . $fn, "."))); if ($ext == ".jpg" || $ext == ".png") { $orig = imageCreateFromString(file_get_contents(projectPath . '/data/' . $fn)); /*} else if($ext==".png") { $orig = imageCreateFromPng(projectPath.'/data/'.$fn); */ } else { die("Wrong extension."); } $Wo = $w; $f = $w / imageSx($orig); $Ho = imageSy($orig) * $f; if ($square == 1) { $Ho = $Wo; } $W = (int) $Wo; if ($W < 10) { $W = 100; } $H = (int) $Ho; if ($H < 10) { $H = 100; } $im = imageCreateTrueColor($W, $H); $wh = imageSx($orig); $w2 = imageSx($orig); $h2 = imageSy($orig); if ($square == 1) { if ($w2 > $h2) { $w2 = $h2; } else { $h2 = $w2; } } $cn = 'data/cache/' . md5($fn . $w . $h) . ".jpg"; imagecopyresampled($im, $orig, 0, 0, imageSx($orig) / 2 - $w2 / 2, imageSy($orig) / 2 - $h2 / 2, $Wo, $Ho, $w2, $h2); if ((int) $rot != 0) { $im = imagerotate($im, $rot * -90, 0); } if ($watermark) { $this->addWatermark($im); } imageJpeg($im, projectPath . '/' . $cn, 90); return $cn; }