Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFR]Whether can add an image class. #902

Closed
dreamsxin opened this issue Jul 24, 2013 · 12 comments
Closed

[NFR]Whether can add an image class. #902

dreamsxin opened this issue Jul 24, 2013 · 12 comments

Comments

@dreamsxin
Copy link
Contributor

Functions are as follows:

class Image {

        /**
         * Resize the image to the given size. Either the width or the height can
         * be omitted and the image will be resized proportionally.
         *
         *     // Resize to 200 pixels on the shortest side
         *     $image->resize(200, 200);
         *
         *     // Resize to 200x200 pixels, keeping aspect ratio
         *     $image->resize(200, 200, Image::INVERSE);
         *
         *     // Resize to 500 pixel width, keeping aspect ratio
         *     $image->resize(500, NULL);
         *
         *     // Resize to 500 pixel height, keeping aspect ratio
         *     $image->resize(NULL, 500);
         *
         *     // Resize to 200x500 pixels, ignoring aspect ratio
         *     $image->resize(200, 500, Image::NONE);
         *
         * @param   integer  new width
         * @param   integer  new height
         * @param   integer  master dimension
         */
        public function resize($width = NULL, $height = NULL, $master = NULL);

        /**
         * Crop an image to the given size. Either the width or the height can be
         * omitted and the current width or height will be used.
         *
         * If no offset is specified, the center of the axis will be used.
         * If an offset of TRUE is specified, the bottom of the axis will be used.
         *
         *     // Crop the image to 200x200 pixels, from the center
         *     $image->crop(200, 200);
         *
         * @param   integer  new width
         * @param   integer  new height
         * @param   mixed    offset from the left
         * @param   mixed    offset from the top
         */
        public function crop($width, $height, $offset_x = NULL, $offset_y = NULL);

        /**
         * Rotate the image by a given amount.
         *
         *     // Rotate 45 degrees clockwise
         *     $image->rotate(45);
         *
         *     // Rotate 90% counter-clockwise
         *     $image->rotate(-90);
         *
         * @param   integer   degrees to rotate: -360-360
         */
        public function rotate($degrees);

        /**
         * Flip the image along the horizontal or vertical axis.
         *
         *     // Flip the image from top to bottom
         *     $image->flip(Image::HORIZONTAL);
         *
         *     // Flip the image from left to right
         *     $image->flip(Image::VERTICAL);
         *
         * @param   integer  direction: Image::HORIZONTAL, Image::VERTICAL
         */
        public function flip($direction);

        /**
         * Sharpen the image by a given amount.
         *
         *     // Sharpen the image by 20%
         *     $image->sharpen(20);
         *
         * @param   integer  amount to sharpen: 1-100
         */
        public function sharpen($amount)
        {
                // The amount must be in the range of 1 to 100
                $amount = min(max($amount, 1), 100);

                $this->_do_sharpen($amount);

                return $this;
        }

        /**
         * Add a reflection to an image. The most opaque part of the reflection
         * will be equal to the opacity setting and fade out to full transparent.
         * Alpha transparency is preserved.
         *
         *     // Create a 50 pixel reflection that fades from 0-100% opacity
         *     $image->reflection(50);
         *
         *     // Create a 50 pixel reflection that fades from 100-0% opacity
         *     $image->reflection(50, 100, TRUE);
         *
         *     // Create a 50 pixel reflection that fades from 0-60% opacity
         *     $image->reflection(50, 60, TRUE);
         *
         * [!!] By default, the reflection will be go from transparent at the top
         * to opaque at the bottom.
         *
         * @param   integer   reflection height
         * @param   integer   reflection opacity: 0-100
         * @param   boolean   TRUE to fade in, FALSE to fade out
         */
        public function reflection($height = NULL, $opacity = 100, $fade_in = FALSE);

        /**
         * Add a watermark to an image with a specified opacity. Alpha transparency
         * will be preserved.
         *
         * If no offset is specified, the center of the axis will be used.
         * If an offset of TRUE is specified, the bottom of the axis will be used.
         *
         *     // Add a watermark to the bottom right of the image
         *     $mark = Image::factory('upload/watermark.png');
         *     $image->watermark($mark, TRUE, TRUE);
         *
         * @param   object   watermark Image instance
         * @param   integer  offset from the left
         * @param   integer  offset from the top
         * @param   integer  opacity of watermark: 1-100
         */
        public function watermark(Image $watermark, $offset_x = NULL, $offset_y = NULL, $opacity = 100);

        /**
         * Set the background color of an image. This is only useful for images
         * with alpha transparency.
         *
         *     // Make the image background black
         *     $image->background('#000');
         *
         *     // Make the image background black with 50% opacity
         *     $image->background('#000', 50);
         *
         * @param   string   hexadecimal color value
         * @param   integer  background opacity: 0-100
         */
        public function background($color, $opacity = 100);

        /**
         * Save the image. If the filename is omitted, the original image will
         * be overwritten.
         *
         *     // Save the image as a PNG
         *     $image->save('saved/cool.png');
         *
         *     // Overwrite the original image
         *     $image->save();
         *
         * @param   string   new image path
         * @param   integer  quality of image: 1-100
         * @return  boolean
         */
        public function save($file = NULL, $quality = 100);

        /**
         * Render the image and return the binary string.
         *
         *     // Render the image at 50% quality
         *     $data = $image->render(NULL, 50);
         *
         *     // Render the image as a PNG
         *     $data = $image->render('png');
         *
         * @param   string   image type to return: png, jpg, gif, etc
         * @param   integer  quality of image: 1-100
         * @return  string
         */
        public function render($type = NULL, $quality = 100);

}
@ghost
Copy link

ghost commented Jul 24, 2013

Does this one come from Kohana?

@dreamsxin
Copy link
Contributor Author

Yes, I am a fan of Kohana.

@dreamsxin
Copy link
Contributor Author

I also want to join the QR Code, though a bit inappropriate. Can you help me @sjinks ?
https://github.com/dreamsxin/qrencodeforphp

$qr = qr_encode('test for qrcode');
if (is_resource ($qr))
    qr_save ($qr, '1.png');

$qr = qr_encode ('test for qrcode');
if (is_resource ($qr))
{
    header ("Content-type: image/PNG");
    qr_save ($qr);
}

<?php
$qr = qr_encode ('test for qrcode', 1, QR_ECLEVEL_M, QR_MODE_KANJI, 1);
if (is_resource ($qr))
{
    header ("Content-type: image/PNG");
    qr_save ($qr);
}

@ghost
Copy link

ghost commented Jul 26, 2013

What do you think if we implement the Image class together? I will guide you through the process and correct the mistakes but leave the implementation to you.

@dreamsxin
Copy link
Contributor Author

@sjinks It is my pleasure, I am very happy to get your help.

@dreamsxin
Copy link
Contributor Author

@sjinks I have create branch https://github.com/dreamsxin/cphalcon/tree/image_class, How to start?
Also use the adapter, GD and Imagick

@ghost
Copy link

ghost commented Jul 29, 2013

@dreamsxin I will get back to you shortly — need to finish something first

@dreamsxin
Copy link
Contributor Author

@sjinks OK. I am from now will be online 8 hours.

@ghost
Copy link

ghost commented Jul 30, 2013

@dreamsxin Please add me to GTlak — my ID is vbkolesnikov(at)gmail(dot)com

@dreamsxin
Copy link
Contributor Author

@sjinks My ID dreamszhu(at)gmail(dot)com

@dreamsxin
Copy link
Contributor Author

@sjinks I to the image class has not clear thinking, the implementation of the final structure such as GD, Imagick how to call, I now is to imitate the Logger class, Under the guidance of the time to help me.

$image = new Phalcon\Image\Adapter\GD('5.jpg');

var_dump($image);

display:

object(Phalcon\Image\Adapter\GD)#1 (1) {
  ["_imageinfo":protected]=>
  array(7) {
    [0]=>
    int(1600)
    [1]=>
    int(900)
    [2]=>
    int(2)
    [3]=>
    string(25) "width="1600" height="900""
    ["bits"]=>
    int(8)
    ["channels"]=>
    int(3)
    ["mime"]=>
    string(10) "image/jpeg"
  }
}

This was referenced Aug 7, 2013
@phalcon
Copy link
Collaborator

phalcon commented Aug 9, 2013

Implemented in 1.3.0, thanks

@phalcon phalcon closed this as completed Aug 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant