PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun May 31, 2020 2:10 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Oct 07, 2015 9:21 am 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
Hey guys i have configured my laravel project to have the imagine package , i have used the steps defined HERE to configure my laravel project .

I have the following code in my view:

Syntax: [ Download ] [ Hide ]
<div id="admin">

    <h1>Products Admin Panel</h1><hr>

    <p>Here you can view, delete, and create new products.</p>

    <h2>Products</h2><hr>

    {{ Form::open(array('url'=>'admin/fileupload/create' , 'files'=>true)) }}
    <p>
        {{ Form::file('image') }}
    </p>
    {{ Form::submit('Create Product' , array('class'=>'secondary-cart-btn')) }}
    {{ Form::close() }}

</div>  <!-- end admin -->
 


and i have the below code in my controller:

Syntax: [ Download ] [ Hide ]
public function postCreate() {

             $fileupload = new Fileupload;
       
             $height = 200;
             $width = 400;
             $mode   = ImageInterface::THUMBNAIL_OUTBOUND;
             $size   = new Box($width, $height);

             $image = Input::file('image');
             $filename = date('Y-m-d-H-i-s')."-".$image->getClientOriginalName();
             $path = public_path('img/testsave/' .$filename);
             $thumbnail   = Imagine::open($path ."jpg")->thumbnail($size, $mode);    
             $fileupload->save();
       
            return Redirect::to('admin/products/index')
                ->with('message' , 'Product created');
    }
 


I am not sure what the below line really does:

Syntax: [ Download ] [ Hide ]
$mode   = ImageInterface::THUMBNAIL_OUTBOUND;
 


So i beleive i can used Imagine meathods like so:

Syntax: [ Download ] [ Hide ]
Imagine::open
 


I get the following error as of now , when i click the submit button

,

Is the code in my controller correct ? what am i doing wrong ? :(

My objective is to grab the image once the user presses submit , change the name and use imagine to resize the image. and save it.


Top
 Profile  
 
PostPosted: Wed Oct 07, 2015 9:31 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Looks like you're getting a 404 there, rather than a problem with Imagine itself. Can you confirm via HTTP response codes?

_________________


Top
 Profile  
 
PostPosted: Wed Oct 07, 2015 9:36 am 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331


Top
 Profile  
 
PostPosted: Wed Oct 07, 2015 9:50 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Through your browser's developer tools is probably easiest.


Attachments:
Screen Shot 2015-10-07 at 10.50.47 AM.png
Screen Shot 2015-10-07 at 10.50.47 AM.png [ 196.47 KiB | Viewed 8061 times ]

_________________
Top
 Profile  
 
PostPosted: Wed Oct 07, 2015 9:55 am 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
Thanks for the handy trick :D will try it


Top
 Profile  
 
PostPosted: Wed Oct 07, 2015 9:58 am 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
Heres what i get .


Top
 Profile  
 
PostPosted: Wed Oct 07, 2015 10:04 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
So your POST route is failing. I'd check the form action first and foremost.

_________________


Top
 Profile  
 
PostPosted: Thu Oct 08, 2015 3:39 am 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
your right , was using get , instead of post :

Route::get('admin/fileupload/create' , array('uses' => 'FileuploadController@postCreate'));

changed that to

Route::post('admin/fileupload/create' , array('uses' => 'FileuploadController@postCreate'));


Top
 Profile  
 
PostPosted: Mon Feb 08, 2016 7:29 am 
Offline
Forum Newbie

Joined: Thu Feb 04, 2016 2:19 am
Posts: 7
Hey, try this code :

<?php
$source = 'image.jpeg';
$destination = 'resize.jpg';
$width = 300;
$height = 500;

$imagine = new Imagine\Gd\Imagine();
$size = new Imagine\Image\Box($width, $height);
$mode = Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$resizeimg = $imagine->open($source)
->thumbnail($size, $mode);
$sizeR = $resizeimg->getSize();
$widthR = $sizeR->getWidth();
$heightR = $sizeR->getHeight();

$preserve = $imagine->create($size);
$startX = $startY = 0;
if ( $widthR < $width ) {
$startX = ( $width - $widthR ) / 2;
}
if ( $heightR < $height ) {
$startY = ( $height - $heightR ) / 2;
}
$preserve->paste($resizeimg, new Imagine\Image\Point($startX, $startY))
->save($destination);


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group