spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Create square 1:1 thumbnail in PHP


Use this code this code uploads image to folder and renames the file and thumb will be created with same name

HTML

<INPUT NAME="userfile[]" TYPE="file">

image directory "upimg/"
thumb directory thimg

php processing

$rename = md5(rand() * time());
        $add = "upimg/" . $rename .
$_FILES['userfile']['name'];
        if
(move_uploaded_file($_FILES['userfile']['tmp_name'],
$add)) {
            echo "Successfully uploaded the
image";
            chmod("$add", 0777);
        } else {
            exit;
        }
        $n_width = 200;
        $n_height = 200;
        $tsrc = "thimg/" . $rename .
$_FILES['userfile']['name'];
        if (!($_FILES['userfile']['type'] ==
"image/jpeg" OR $_FILES['userfile']['type'] ==
"image/gif")) {
            exit;
        }
        if ($_FILES['userfile']['type'] ==
"image/gif") {
            $im = ImageCreateFromGIF($add);
            $width = ImageSx($im);
            $height = ImageSy($im);
            $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);
            } elseif
(function_exists("imagejpeg")) {
                Header("Content-type:
image/jpeg");
                ImageJPEG($newimage, $tsrc);
            }
            chmod("$tsrc", 0777);
        }
        if ($_FILES['userfile']['type'] ==
"image/jpeg") {
            $im = ImageCreateFromJPEG($add);
            $width = ImageSx($im);
            $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", 0777);
        }

Categories : PHP

Related to : Create square 1:1 thumbnail in PHP
How can i change meta (alt and tilte) in catalog thumbnail , product thumbnail ? - Woocomerce
Try this : add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2); function change_attachement_image_attributes( $attr, $attachment ){ // Get post parent $parent = get_post_field( 'post_parent', $attachment); // Get post type to check if it's product $type = get_post_field( 'post_type', $parent); if( $type != 'product' ){ retu

Categories : PHP
Create thumbnail for display OR Load 50% of image and create image preview
use the following code to create thumb nail images, You can create all type of image file jpeg, png, gif $orig_directory = "$desired_dir"; //Full image folder $thumb_directory = "thumb/"; //Thumbnail folder /* Opening the thumbnail directory and looping through all the thumbs: */ $dir_handle = @opendir($orig_directory); //Open Full image dirrectory if ($dir_handle >

Categories : PHP
Why does the thumbnail I create have a larger file size than the original image?
The thumbnail you create has 4 times the bit depth of the original. Reducing the bit depth will reduce the file size. Edit: To reduce the bit-depth is quite simple, but I can't see any way to do this via CodeIgniter: $im = imagecreatefrompng('./original.png'); imagetruecolortopalette($im, false, 256); imagepng($im, './output.png'); However, this file is still larger than the original (~

Categories : PHP
How do I take a list in one function (num), and square the values in another (square)?
Although this question is too broad, I will take a stab at answering it. Let's assume your list is generated in the function read_file below. The return num_list allows num_list to be available to the caller - the script in this case. We now have another function square which accepts a list of numbers and returns another list containing the squares of the input list. Here's the file my_numbers.t

Categories : Python
Creating and saving a thumbnail in array using php
The problem in your code is in this line: if (($img = @imagecreatefromstring($files[$i])) !== FALSE) { ... } It seems that statement was never been executed. To obtain an image from a file using it's filename, you should use imagecreatefromjpeg function. So your code inside loop should look like: $img = imagecreatefromjpeg($files[$i]); $width = imagesx($img); $height = imagesy($img); $boxSi

Categories : PHP
Recently Add
Cartesian product of associative array showing key and value - PHP
Datamapper orm save and update not working
find methods in COM object
PHP Keyword search not working with multiple words
Set a total based on items ordered, two types, and sometimes one type will not be ordered.
FB request to join a group, going around their official SDK
Using Google charts with php data?
OAuth2 integration with ExactOnline
libvirt-php receives the error: unable to connect to server Permission denied
How to echo results by sets of 2?
Why does PHP's sprintf not round 5s reliably?
php replace affects on replaced string
PHP Find and replace multiple similar entries
Replace PHP date output with pre-made images
How to install Laravel 4 packages on Windows
Using updateOrCreate for multiple data insert in Laravel
Storing products in a MYSQL database and then search and filter them?
Create order with PrestaShop's API
how to get latest messages from all users
Yii CMultiFileUpload Restrict Image width
Combine array by key factor
Semicolon after if condition in PHP - code still works
Get date using day of the week
soap web service with symfony
Seasonal Reservation system Day/month
is it possible to join a single table it self?
Attempting to compare two arrays PHP
Sticky Select Option
Eventbrite duplicate event entry
Pagination Not Working on custom post type in Wordpress
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.